Error 1045 in Navicat and SQLyog

MySQL
Database
Debugging
Archive
Fix MySQL Error 1045 access denied in Navicat or SQLyog by granting remote host privileges to the MySQL user — includes per-IP and wildcard GRANT commands.
Author

B. Talvinder

Published

February 12, 2015

From the Archive

Originally published in 2015 on talvinder.com. Some technical details may be outdated, but this remains here as part of the archive.

If you’ve experienced “Access denied” while using Navicat or SQLyog or any other MySQL client, this post is for you.

I’m assuming that the username and password are working fine when you SSH into the machine.

Usually this happens because by default the user only has privileges to access mysql-server on localhost and not via remote. The same user in MySQL has to be given access to both localhost and remote. Here are the steps for Ubuntu:

Run this command to grant access from all machines:

GRANT ALL PRIVILEGES ON *.* TO 'USERNAME'@'%' IDENTIFIED BY 'PASSWORD' WITH GRANT OPTION;

Or grant access from a specific IP:

GRANT ALL PRIVILEGES ON *.* TO 'USERNAME'@'1111.2222.3333.4444' IDENTIFIED BY 'PASSWORD' WITH GRANT OPTION;

You can run the above command multiple times to grant access from multiple IPs. You can also specify a separate username and password for remote access.

Check the final outcome:

SELECT * FROM information_schema.user_privileges WHERE grantee LIKE "'USERNAME'%";

Finally, run:

FLUSH PRIVILEGES;

Check the connection – it should work.

Enjoyed this?

Get frameworks, build logs, and field notes in your inbox.

No spam. Unsubscribe anytime.