Error:
Shows error: Client does not support authentication protocol requested by server. Consider creating my SQL client
State: accessing the data of MySQL database using node js and express js while implementing react application
Code:
index.js
import express from 'express'
import mysql from 'mysql'
const app = express()
const db = mysql.createConnection({
host:"localhost",
user:"root",
password:"mysql1234",
database:"bookshop"
})
app.get("/",(req,res)=>{
res.json("Hello backend is here")
})
app.get("/books", (req, res)=>{
const q = "SELECT * FROM books"
db.query(q, (data,err)=>{
if(err){
return res.json(err)
}
return res.json(data)
})
})
app.listen(8181,()=>{
console.log("Backend connected")
})
Solution 1:
paste the following code in the workbench and replace your password
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'your_mysql_password';
Solution 2:
install mysql2 in your server app
npm i mysql2