I am trying to connect to a remote mysql database from my local box. Initially I was not even able to hit the mysql db. But after commenting the binding_address in the my.cnf file and restarting the mysql server, I am now able to hit it.
But now, I am getting an Access denied error
mysql -u root -h x.x.x.x -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'x.x.x.x' (using password: YES)
Is my IP being blacklisted or something? I can change that since I have admin permission on the remote box. Somebody help me.
First order of business is getting in with full permissions. If you cannot, add this line to your my.cnf and restart mysql:
I recommend doing a little recon to see what users you have:
This will display your users list, something like:
You need to see localhost in the list. If you do not, add it like this:
Otherwise simply update the password like this:
Then remove skip-grant-tables from your my.cnf and restart mysql.
Double check to make sure root has access from hosts/IPs other than localhost.
If it returns just one row with "localhost", you need to grant permissions to the IP you are connecting from.
Replace mydatabase with the database you want access to (or put in a wildcard), then replace the IP with the address or subnet your client is connecting from.
Passwords in
mysql
are setup per IP. Usually they are only set for access via localhost only, especially for the root user. Verify that there is aroot@%
entry setup in your permissions table.If you really do need to allow remote root access, then please consider changing the username so that people can't easily guess your servers superuser account.
For Unix like systems the following solution worked for me to reset the root password: http://www.cyberciti.biz/tips/recover-mysql-root-password.html
Jist:
Recover MySQL database server password with following five easy steps:
Stop the MySQL server process.
Start the MySQL (mysqld) server/daemon process with the --skip-grant-tables option so that it will not prompt for password.
Connect to mysql server as the root user.
Setup new mysql root account password i.e. reset mysql password.
Exit and restart the MySQL server.
Specific commands: (login as the root user):
Stop mysql service
Output:
Start to MySQL server w/o password:
use mysqld_safe:
Output:
Connect to mysql server using mysql client:
Output:
Setup new MySQL root user password
Stop MySQL Server:
Output:
Start MySQL server and test it:
Its possible that you need to grant privileges for that IP, an example would be:
mysql> GRANT ALL PRIVILEGES on dbname.* to root@'%'; mysql> FLUSH PRIVILEGES;
grants to all IPs
Unfortunately mysql permissions distinguish by host and ip. Permissions granted for a hostname do not work for an IP and vice versa.
Make sure you grant permissions for the user and host ip/host name you are connecting from.