node连接mysql:Client does not support authentication protocol requested by server; consider upgrading

When using node to connect to the mysql database today, I wrote the following code;

const mysql = require('mysql');

const db = mysql.createPool({
    host: 'localhost', 
    user: 'root',  
    password: '123456', 
    database: 'test01' 
})

db.query('SELECT 1', (err, res) => {
    console.log(err)
    console.log(res)
})

Then when running, an error is reported, the error message:

'Client does not support authentication protocol requested by server; consider upgrading MySQL client

 Then there are small eyes, big confusion. . . Find the cause of the problem at a time;

Mysql version 8.0 and above has replaced a new password authentication method, and the node client does not support the new authentication method

Solution:

mysql2 - npm

To install mysql2, run the command:

npm install --save mysql2
const mysql = require('mysql2');

Run the project again:

Guess you like

Origin blog.csdn.net/qq_42543244/article/details/126520858