Enable remote root connection to your MySQL server

Enable remote root connection to your MySQL server

Last updated:

Grant access to a specific user using a specific IP to your database

This will enable you (and everyone else who knows you password) to log in as root to your remote MySQL Server:

(don't do this for production servers because it may enable an attacker to gain control of your database!)

  • log into your machine where the MySQL server is located:
  ssh <your_username>@<server_address>
  • log into MySQL as root:

    mysql -u root -p

  • type your password;

  • Grant access to the user

  grant all on *.* to root@'<source__ip>' identified by '<password>';

where <source_ip> is the ip you want to connect from and <password> is the password you want to use.

Grant access to all users within an IP range

grant all on *.* to root@'192.168.1.%' identified by '<password>';

Troubleshooting

If you still can't connect after doing this, have a look at file /etc/mysql/my.cnf on the server. Make sure that you have option bind-address set as follows:

bind-address  = 0.0.0.0