2

I'm trying to connect to a database that I have up on my domain. I've created a user called public_guests which can access this database.

I'm using NodeJS to create a connection but I get the following error.

ER_ACCESS_DENIED_ERROR: Access denied for user

The error is followed by my IP address etc.

Here is my code:

mysql = require("mysql");

var connection = mysql.createConnection({
    host: "humadshah.com",
    username: "public_guests",
    password:"hello",
    databse:"my_quotes"
});

connection.connect(function(error){
    if(error){
        console.log("Couldn't connect :(    Error: " + error);
    } else {
        console.log("Connected successfully~!");
    }    
});

I've never used a database before, so I'm expecting this to be a really stupid mistake somewhere.

3
  • 7
    I'll buy a beer for anyone that solves this in under an hour Commented Sep 25, 2016 at 2:47
  • 2
    Your code is irrelevant. Your password is wrong, your user is not allowed from that IP, or something else. Also, your MySQL host is open to the entire world to connect to. This isn't great practice. While you do need proper credentials to get in, it's still likely that a new MySQL vulnerability will be found one day. Don't open this up so broadly unless you have to. Finally, if this is your first database, might I suggest PostgreSQL? Latest version of Postgres supports document style storage as well as columnar, and has many other nice features. Commented Sep 25, 2016 at 3:03
  • 1
    @Drew Looks like they're using GoDaddy. GoDaddy sets the default password to something random, so it might take more than an hour. ;-) Commented Sep 25, 2016 at 3:10

4 Answers 4

2

As I think, it's not the problem of Node.js.

it's permissions issue which user has at particular IP address, and in the error message is stated:

Access denied for user @some IP

So try to give your root permission for IP where your Node.js instance is running port xxx.xx.xx.xx.

Sign up to request clarification or add additional context in comments.

6 Comments

Is there a way I can give permission to all IPs? I want this database to be accessed by anyone from anywhere
@HumanCyborgRelations Yes, that's possible... is that really what you want? Use user@%.
Thanks for the response! Yes, that works. I'm going to only allow users to select the data in the tables, and not alter them in any way. Is there a risk I should be worried about?
@HumanCyborgRelations I guess it depends on what's in those tables, and how sure you really are that you can secure the MySQL server. At a minimum, it's pretty easy to tie up your server so that nobody else can access data. Locks and such are really annoying that way.
|
1

Its permission issue only, grant required permission to user it will work.

Comments

0

In my case there were two objects of JSON. First was test and second was development but dbPassword were not same. I changed them to one unique password and then it works. That type of problem usually occurs with beginners.

Comments

0

Just create a new user from workbench and use it for your nodejs project

CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON * . * TO 'newuser'@'localhost';
FLUSH PRIVILEGES;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.