Node connection Mysql error ER_NOT_SUPPORTED_AUTH_MODE

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

d296375c002442e79380254ad711f9b0.png

 


 2. After entering the password, this page will appear24e0d6826ab3490faa074028baf32d2d.png

 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

1211f09a6ebf4ffc9735145b0dcaf8b6.png

 

4. After execution, the following results will appear

ee831ef3d7b841ab85ab611f557c8071.png 

5. Finally, execute the command    flush privileges ; if the reported result is as follows, it means success

aa7a2125bd4046baa6b0b97e857850e3.png

 

 

Guess you like

Origin blog.csdn.net/Ass12454548/article/details/129446272