skip to Main Content

I’m trying to connect my MySQL database, set up using this tutorial
https://dev.mysql.com/doc/workbench/en/wb-getting-started-tutorial-creating-a-model.html
Along with creating the model, I created a running server using the tutorial listed in the model tutorial. I’ve created a table inside of it and populated it with a few values.

Now I’m trying to use the javascript library mysql, this is my code:

var mysql = require('mysql');

var con = mysql.createConnection({
  host: "localhost",
  user: "admin",
  password: "mypassword",
  database: "album"
});

con.connect(function(err) {
    if (err) throw err;
    console.log("Connected!");
  });

I get the error "Error: ER_DBACCESS_DENIED_ERROR: Access denied for user ‘admin’@’localhost’ to database ‘album’"

I looked into this issue and have tried everything I could find to fix it. I’ve gotten rid of the database field in the call, passed in an empty string as the password, added more users with different ids/passwords and tried to get in that way. I’ve used the
ALTER USER ‘admin’@’localhost’ IDENTIFIED WITH mysql_native_password BY ‘mypassword’;
which didn’t seem to change any of the permissions associated with the ‘admin’ user.

"admin" was the name I set for the main user in my DB. The DB is called MyFirstConnection and the Schema is called "album". Any advice helps!

2

Answers


  1. You can grant necessary privileges to a user using SQL commands in the MySQL Workbench if you have access to that. For example, to grant all privileges to the ‘admin’ user for the ‘album’ database:

    GRANT ALL PRIVILEGES ON album.* TO 'admin'@'localhost';
    FLUSH PRIVILEGES; 
    

    Another problem might be that the username is ‘admin’, in my experience it has often been ‘root’ by default.

    Login or Signup to reply.
  2. Check the mysql settings in the my.cnf configuration file at the following point:

    • The bind-address configuration parameter must be set to
      127.0.0.1 or 0.0.0.0 , if you are commenting #bind-address remove the # and look like this:

      bind-address = 0.0.0.0

    If your server is Linux, it is in the /etc/my.cnf or /etc/mysql/my.cnf folder

    After changing the binding address, don’t forget to restart your MySQL server (Linux command):

    sudo service mysql restart

    Note: If the bind-address parameter is set to 127.0. 0.1 or localhost, then MySQL is only listening on the localhost. Change the bind-address value to 0.0.0.0 to enable the MySQL database server to listen on all network interfaces.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search