How do I Allow Remote Access to MySQL for Specific Users to My Virtual/Dedicated/Cloud Server

How to Allow Remote Access to MySQL Server for a User/IP/Database

For your application/requirements you may want to selectively allow MySQL Access from Remote (off-server) Locations.
  1. Connect to your Server over SSH
  2. Login to MySQL as the MySQL-Root user:
    mysql -uroot -p
    >mysql GRANT ALL PRIVILEGES ON *.* TO [username]@[ip-address] IDENTIFIED BY "[password]";
    (replace [username] [ip-address] [password] as required - you can use % instead of an IP to allow from any IP)
    e.g. >mysql GRANT ALL PRIVILEGES ON *.* TO MySQLExternalUser@% IDENTIFIED BY "SecurePassw0rdz!";
    >mysql FLUSH PRIVILEGES;
    >mysql quit
  3. Allow MySQL through FireWall (iptables) where installed
    iptables -I INPUT -s (yourip)/(yoursubnet) -j ACCEPT
    iptables -A INPUT -p tcp -m tcp --dport 3306 -j ACCEPT
    iptables-save
  4. Configure MySQL to Allow Remote Connections
    nano -w /etc/my.cnf
    add 'bind-address={server-ip-address}'
  5. Switch off SELinux Enforcing Mode
    echo 0 > /selinux/enforce
    nano -w /etc/selinux/config
    change 'SELINUX=enforcing' to your choice of disabled or permissive

After a reboot your server will allow the defined users/ips to remotely connect to the MySQL Server.

  • 12 Users Found This Useful
Was this answer helpful?

Related Articles

What are the exact specs of your hardware?

We do not disclose the full hardware specifications of our servers, as they are eachy...

How do I stop Cpanel reporting /usr/bin/crontab permissions are wrong. Please set to 4755.

If you get this message in CPanel when adding/ediiting/viewing the cron jobs ......

How do I force Statistics (Webalizer and AWstats) to run on Plesk Servers ?

Updating Webalizer and AWStats on Linux Plesk Servers from SSH The plesk control panel is...

How much is HELM ? What Helm licences do you offer ?

Web Host Automation (HELM Authors) sold the control panel rights and code some years ago to...

How do I install or update Xen Tools on a Linux VPS?

Login to your VPS as root (or use "su -" from a user account). Enter the following commands: #...

Powered by WHMCompleteSolution