I am attempting to connect to mySQL through a NodeJS file, but I receive the following error:
{ Error: ER_ACCESS_DENIED_ERROR: Access denied for user \'root\
Create new user (instead of using root) fixed my problem.
mysql> CREATE USER 'new_user'@'%' IDENTIFIED BY 'password';
Query OK, 0 rows affected (0.00 sec)
Then grant:
mysql> GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, PROCESS, REFERENCES, INDEX, ALTER, SHOW DATABASES, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER ON *.* TO 'new_user'@'%' WITH GRANT OPTION;
Then change the credentials:
var connection = mysql.createConnection({
host : 'The mysql IP',
port : 'The mysql Port',
user : 'new_iser',
password : 'new_user_pass',
database : 'database-name'
});
I have faced this issue by giving the full user name in the user section when I changed the 'root'@'localhost' to 'root' It is working fine now.
var mysql = require('mysql');
var con = mysql.createConnection({
host: hostname,
user: "root",
password: "rootPassword"
});
con.connect(function(err) {
if (err) throw err;
console.log("Connected!");
});
Add skip-grant-tables in my.ini (this file is available in default installation path of mysql)
[mysqld]
skip-grant-tables
port=3306
You need to make sure that the username you are using is matched against the ip address you are using under host name for connection.
I had the same error from nodejs script, so i removed password parameter and now it magically works fine
var mysql = require('mysql');
var connection = mysql.createConnection({
host: 'localhost',
user: 'root'
});
Best Solution to resolve this problem:
You got this Error : ER_NOT_SUPPORTED_AUTH_MODE this is error is mentioning when you install sql server you selected"strong authentication", but you set a weak password. You need to reset strong password or need to choose legacy authentication method.
Follow these steps to choose legacy authentication method...
You installed mysql server using "mysql installer"
Open "MySQL Installer".
Click "Reconfigure" MySQL server under Quick Action.
Click next to maintain current configurations under "High Availability".
Click next to maintain current configurations under "Type and Networking"
Select radio button "Use Legacy Authentication Method" under "Authentication Method" and click next.
Enter root account password and click on check. Wait a while for verification of password and click next.
Click next to apply configurations and restart the database server.
Now run code:
var mysql = require('mysql');
var connection = mysql.createConnection({
host: 'localhost',
user: 'root',
password: 'password'
)};
Password field should be replaced with root password.