0
我有一個文件con_mysql.js
,內容如下:Node.js的連接mysql錯誤
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
謝謝,完成了!爲什麼客戶端有connect()方法; – chris
這太棒了:)嗯...也許它仍然有connect()方法,這樣仍然在代碼中使用它的人(就像你自己)不只是得到一些「未知函數」的錯誤,而是該方法已棄用的更詳細的消息。 – mwerner