I have setup a MySQL database. When I try to access it through my Node JS server, I am getting the error
\"ER_NOT_SUPPORTED_AUTH_MODE: Client does no
var connection = mysql.createConnection({
host : 'localhost',
user : 'root',
password : '********',
database : 'vod_bill_database',
port : 3308
});
I had the same error and since i changed my port in phpmyadmin from 3306 to 3308 therefore here also i had to write port: 3308 and it started working.
try the older version of mysql like 5.6.40, it uses by default SHA256_password auth where new version 8.0. uses by default sha2_password auth which is more secure and throw this authentication protocol error. MYSQL installer 5.6.40
just create a new user on MySQL
CREATE USER 'foo'@'localhost' IDENTIFIED WITH mysql_native_password BY 'bar';
1st run this code ->
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
2nd
flush privileges;
yellow yow bros !
// mysql.ts
const pool = mysql.createPool({
connectionLimit: 10,
host: "localhost",
user: "root",
password: "password",
database: "rest-resume-api",
});
and then I have a docker-compose file such as
# docker-compose.yml
version: '3.3'
services:
db:
image: mysql
restart: always
command: --default-authentication-plugin=mysql_native_password
environment:
MYSQL_DATABASE: 'rest-resume-api'
MYSQL_USER: 'root'
MYSQL_ROOT_PASSWORD: 'password'
ports:
- '3306:3306'
expose:
- '3306'
volumes:
- my-db:/var/lib/mysql2
volumes:
my-db:
I figured that in some MySQL versions they have the authentication for the establishment of a connection a bit messed. All I had to do was add the line "insecureAuth : true" to my connection attempt.
var connection = mysql.createConnection({
host : 'localhost',
user : 'root',
password : '********',
database : 'vod_bill_database',
insecureAuth : true
});
It is working fine now.