连接到any-db-mysql的数据库名称不正确
在使用string的节点模块中,当我写一个空格时(通过按空格键),我得到:
%20
而当我写:
\n
我得到:
%0A
我的string中的空格发生了什么? 我真的需要使用空格。
这与URL编码有关吗?
PS:我不介意把一个奇怪的章程组合写出空间,但我不想在控制台中看到%20。
var q=require('any-db-mysql'); q.createConnection('-u my_user -h localhost -D dbname --password[=mypass]',function(e,r){ cosole.log(e); });
的console.log:
Error: ER_WRONG_DB_NAME: Incorrect database name 'u%20my_user%20-h%20localhost%20-D%20dbname%20--password[=mypass]'
它也使“ü”只是“你”。
为什么?
连接string应该如下所示:
q.createConnection('mysql://my_user:mypass@localhost/dbname', function (e, r) { // ... });
或者,也许整洁,你可以使用一个对象:
var options = { host : 'localhost', user: 'my_user', password: 'mypass', database: 'dbname' }; q.createConnection(options, function (e, r) { /* ... */ });
有关示例,请参阅https://github.com/grncdr/node-any-db-adapter-spec和https://github.com/felixge/node-mysql 。
使用decodeURI来获得你的空间
var str = "theSpace%20space"; console.log(decodeURI(str));