MySQL Adding a remote user

02 Dec 2007
Posted by editor

Occasionally I have found a need to connect to certain MySQL tables or Databases remotely. Obviously such a connection presents a security risk and generally it is best to restrict remote users to a specific ip address. This can be done with a firewall rule and/or MySQL provides a way to restrict the user by host. This is how I set up a remote MySQL user. login to your mysql and issue the following command:

GRANT ALL PRIVILEGES ON *.* TO USERNAME@IP IDENTIFIED BY "PASSWORD";

ALL grants all priveleges, restrict by being specific. USERNAME is the username that you would like to create. *.* is the wildcard table.database pair. Be specific to restrict. IP is the public IP address of your remote connection. PASSWORD is the password you would like to use for this username. Note that the ip is the ip address the user will be connecting from. The above scenario has granted ALL privileges to the remote user. Normally it is best to restrict the privileges to only those that are absolutely essential - and no more. You now must flush MySQL's privileges. Run this command:

FLUSH PRIVILEGES;

Tags: