gpt4 book ai didi

mysql - Node.js连接mysql错误

转载 作者:行者123 更新时间:2023-11-29 08:52:04 25 4
gpt4 key购买 nike

我有一个文件 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

最佳答案

deprecated: connect() is now done automatically.



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

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

关于mysql - Node.js连接mysql错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10893654/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com