My system is installed with the mysql-installer-community-8.0.18.0.msi version, and then I use node-mysql locally to connect to the database.
var mysql = require('mysql');
var connection = mysql.createConnection({
host : 'localhost', //本机地址
user : 'root', //用户
password : '123456', //密码
port: '3306', //端口号
database: 'test' //要连接的数据库
});
connection.connect();
var sql = 'SELECT * FROM table1'; //查询table1表的所有数据
connection.query(sql,function (err, result) {
if(err){
console.log('[SELECT ERROR] - ',err.message);
return;
}
console.log('--------------------------SELECT----------------------------');
console.log(result);
console.log('------------------------------------------------------------\n\n');
});
connection.end();
run node test.js
Execute the following results:
F:\All Project\test\node>node test.js [SELECT ERROR] - ER_NOT_SUPPORTED_AUTH_MODE: Client does not support authentication protocol requested by server; consider upgrading MySQL client
报错: [SELECT ERROR] - ER_NOT_SUPPORTED_AUTH_MODE: Client does not support authentication protocol requested by server; consider upgrading MySQL client
Error reason
Node does not support encryption methods above mysql8.0 .
solution
1. Enter the terminal to log in to mysql, use the name mysql -uroot -p and then enter the password and enter the mysql password to enter. Note the spaces
2. After entering the password, this page will appear
3. Import instruction: alter user 'root'@'localhost' identified with mysql_native_password by '123456';
Change the password after the last by in the first paragraph to your own password and press Enter to execute
4. After execution, the following results will appear
5. Finally, execute the command flush privileges ; if the reported result is as follows, it means success