I am trying to connect nodejs with mysql using this simple code:
const express = require('express');
const app = express();
const mysql = require("mysql");
require("dotenv").config();
app.use(express.json());
const connection = mysql.createConnection({
host:'localhost',
user:'root',
password:'root',
database:'test'
});
connection.connect((err)=>{
if(err) throw err;
console.log("Connected to DB);
});
Running code i get my first error:
Client does not support authentication protocol requested by server; consider upgrading MySQL client. Googling about this problem i found the same solution so i followed this link MySQL 8.0 - Client does not support authentication protocol requested by server; consider upgrading MySQL client
Solution says: to execute a query on mysql to alter user ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'root';
but i get error on BY .
This is the message: Missing comma before start of a new alter operation. (near "BY" at position 68)