tags:

views:

21

answers:

1

Hello, 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'

+1  A: 

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.

reko_t
i have no control on the external server we are trying to connect to because it's hosted by another web development company our office hired to build our websites. having said that, i can only suggest things to them.How must one do it if only I need read (SELECT) privilege? I assume the SELECT privilege is enough to be allowed by mysql? And I am just reading the data from their database anyway.
r2b2
For that you'd do `GRANT SELECT ON ...`
reko_t