0

我有一个con_mysql.js包含以下内容的文件:

var client = require('mysql');
client.createClient({'host':'localhost','port':3306,'user':'root','password':'root'});
client.connect();

然后:

# node con_mysql.js

chris:db chris$ node my.js 

/Users/chris/node_modules/mysql/lib/client.js:40
  throw new Error('deprecated: connect() is now done automatically.');
        ^
Error: deprecated: connect() is now done automatically.
    at Client.connect (/Users/chris/node_modules/mysql/lib/client.js:40:9)
    at Object.<anonymous> (/Users/chris/jswork/nodejs/db/con_mysql.js:5:8)
    at Module._compile (module.js:446:26)
    at Object..js (module.js:464:10)
    at Module.load (module.js:353:31)
    at Function._load (module.js:311:12)
    at Array.0 (module.js:484:10)
    at EventEmitter._tickCallback (node.js:190:38)

我该如何解决这个问题?

我已经安装了这样的mysql模块:

# npm install mysql
4

1 回答 1

2

不推荐使用:connect() 现在自动完成。

试试这个:

client.createClient({'host':'localhost','port':3306,'user':'root','password':'root'});

上面的错误表明它将自动连接。您不需要(而且显然不能)调用 connect() 函数。

于 2012-06-05T08:10:34.633 回答