Error connecting to the database: Error: Access denied for user 'new_user'@'localhost' (using password: YES)
Hello,
I'm encountering an issue and could use your assistance.
I'm receiving the following error when attempting to connect to the database:
Here are the steps I've followed:
Created a new database named hello_world_db in MariaDB.
Used the hello_world_db database.
Created a new user named new_user with the password your_password.
Granted all privileges on the hello_world_db database to the new_user user.
Additionally, I've installed the mysql2 package using npm.
1. MariaDB [none]> CREATE DATABASE hello_world_db;
2. MariaDB [(none)]> USE hello_world_db;
3. MariaDB [hello_world_db]> CREATE USER 'new_user'@'localhost' IDENTIFIED BY 'your_password';
4. MariaDB [hello_world_db]> GRANT ALL PRIVILEGES ON hello_world_db.* TO 'new_user'@'localhost';
5. npm install --save mysql2 6 npm install --save mysql2 7 npm install --save mariadb
Then I created a a database connection in my application using a Sequelize instance like this:
import { createConnection } from 'mysql2';
const connection = createConnection({ host: 'localhost', user: 'new_user', password: 'your_password', database: 'hello_world_db' });
connection.connect(function(err) { if (err) { console.error('Error connecting to the database: ', err.stack); return; } console.log('Connected to the database as id ', connection.threadId); });
connection.end();
PS C:\Users\wasab\hello-world> node server.js Error connecting to the database: Error: Access denied for user 'new_user'@'localhost' (using password: YES)
However, when I run node server.js, I still encounter the access denied error.
Your help in resolving this issue would be greatly appreciated.
Thank you.
Answer Answered by Daniel Black in this comment.
Did the grant all privileges fail? Is this 11.3.2 - if so it might be this problem (with solution there)
A fix is coming out next release.