Question

My problem is this command produces an error when I tried to connect from our server to another external server :

mysql -h db.hostname.com -u username -pP@ssword database_name

And this is the error :

ERROR 1044 (42000): Access denied for user 'username'@'%' to database 'database_name'

I already asked the external server admin to add our IP in their firewall but to no avail..

Has this something to do with GRANTing privileges to the 'username'

Was it helpful?

Solution

It's not a problem with firewall, since MySQL is denying the connection. As you suspect, it is a problem with the privileges granted for the user. You need to execute this on the mysql server (you might need to tweak this a bit if you don't want to grant all privileges to the db):

GRANT ALL ON database_name.* TO 'username'@'%' IDENTIFIED BY 'P@ssword';

Also note that if you always connect from a specific host/ip, it's a better idea to specify that host/ip, instead of using a wildcard %, which would allow connections from anywhere.

OTHER TIPS

It sounds like the password is wrong, or that the username you are trying to use is not allowed to connect from your computer's IP address.

as you know, the mysql administrator at the remote site can specify which IP's are allowed to connect using any given user account. Bear in mind that your computer's IP address may be routed through all kinds of routers and firewalls on your company's end before you reach the external database. As a result, your IP may appear different to you than to the external database. In that case, it doesn't help if the external database admin adds YOUR IP to the 'allowed' list, they should add the 'outside world' IP address instead.

The easiest way to find out if this applies to you, is as follows: visit www.whatismyip.com and write down the IP address on screen. This is your IP as seen from the 'outside world'. It is very likely that this IP is actually the outside IP of a firewall or router within your company's network, and not your computer's IP at all.

Next, (assuming you're on Windows) go to Start > run. Type cmd and hit enter. Type ipconfig and hit enter. You can now see your local IP address.

If these two IP's don't match, tell the remote admin to add your outside world IP to the 'allowed' list as well.

also - once you go to production, and move your code to another server, the IP fun starts again. You might as well fix this right away

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top