无法使用nodejs连接到mysql

2o7dmzc5  于 2022-10-31  发布在  Mysql
关注(0)|答案(3)|浏览(146)

{"header":{"type":"auto_translation","ret_code":"error","time_cost":911.0,"request_id":"7e22cfd858da11ed90b038b3e10bcccf"},"message":"Translation error (20001), please retry later. Detail: RuntimeException - The length of source sentence is too long!!! - {\n "header": {\n "time_cost": 0.000328,\n "type": "auto_translation",\n "ret_code": "The length of source sentence is too long!!!"\n }\n}"}

dfty9e19

dfty9e191#

您正在与用户Root连接,我相信它是root。您的错误显然是凭据错误。

a64a0gku

a64a0gku2#

错误:ER_ACCESS_DENIED_ERROR(错误访问被拒绝错误):都是因为得到了允许。
据我所知,你的上述代码,你需要改变根到根

var mysql = require('mysql');

var con = mysql.createConnection({
   host     : 'localhost',
  user     : 'root',
  password : 'my_pass',
});

con.connect(function(err) {
  if (err) throw err;
  console.log("Connected!");
});
p5fdfcr1

p5fdfcr13#

我遇到过一个类似的问题,我可以使用CLI以相同的凭据登录,但不能使用nodejs(mysql-server 8.0)中的mysql2。通过使用%代替localhost解决了这个问题:

CREATE USER 'user'@'%' IDENTIFIED WITH mysql_native_password BY 'password';
GRANT ALL PRIVILEGES ON db.* TO 'user'@'%';

而不是

CREATE USER 'user'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
GRANT ALL PRIVILEGES ON db.* TO 'user'@'localhost';

相关问题