shell和node mysql包的mysql根密码不同

ryevplcw  于 2021-06-18  发布在  Mysql
关注(0)|答案(0)|浏览(220)

出于测试/调试的目的,我最近将我的根mysql密码设置为 root .
我可以从命令行访问mysql服务器,如下所示:

$ mysql -uroot -proot
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 24
Server version: 8.0.12 Homebrew

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

当然,如果我尝试使用空密码,访问将被拒绝

$ mysql -uroot
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

好的,密码现在是root,对吗?
嗯,我试着用 mysql 包(节点),它们提供了一个简单的测试文件。当我像这样使用它时,访问被拒绝:


### FILE `test.js`

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

connection.connect();

connection.query('SELECT 1 + 1 AS solution', function (error, results, fields) {
  if (error) throw error;
  console.log('The solution is: ', results[0].solution);
});

connection.end();

### end of `test.js`

$ node test.js
ER_ACCESS_DENIED_ERROR: Access denied for user 'root'@'localhost' (using password: YES)

我发布这篇文章的原因是,如果我只是将上面的密码更改为空字符串,我将得到预期的输出:

$ node test.js
The solution is:  2

怎么会这样?
细节:
mysql ver 8.0.12 for osx10.13 on x86\U 64(自制)
节点v9.10.1
mysql包版本:2.16

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题