How to: Connect to MySQL Remotely

mysqlEnabling Plesk 12 Remote MySQL Connections

1. Connect to your server via SSH.

2. Log into MySQL.

mysql -u admin -p`cat /etc/psa/.psa.shadow`

3. If you are attempting to grant non-localhost access to a user, you should use this line:

GRANT ALL PRIVILEGES ON dbname.* TO username@'IP' IDENTIFIED BY 'password';

Where:

  • dbname is replaced by the database you’d like to open up (a * here will open up all databases)
  • username is replaced by the user to be allowed access
  • IP is replaced by the actual IP to connect from (a % here will open up to all IPs — NOT RECOMMENDED).
  • password is replaced by the desired password. A blank field here will result in no password (NOT RECOMMENDED).¬†Changing the password for that user listed in Plesk will set it as well.

4. Apply these changes by using the MySQL command:

FLUSH PRIVILEGES;

5. Next, quit MySQL by using this command:

quit

6. You may need to allow the source IP from which you are connecting to connect to port 3306 after granting the privileges inside MySQL. Connect to your server as “root” and issue the following command:

iptables -I INPUT -s -p tcp --dport 3306 -j ACCEPT

Be sure to replace with your IP address.

Was this helpful?
How to: Connect to MySQL Remotely written by UKC average rating 5/5 - 1 user ratings