The purpose of this tutorial is to show how to access MySQL remotely with the root account. Conventional security practice is to disable remote access for the root account, but it is very simple to turn on that access in a Linux system.
Read on and follow through the step by step instructions to allow root remote access in your MySQL server.
In this tutorial you will learn:
- How to allow remote access to the root accout in MySQL
|Category||Requirements, Conventions or Software Version Used|
|Other||Privileged access to your Linux system as root or via the
# – requires given linux commands to be executed with root privileges either directly as a root user or by use of
$ – requires given linux commands to be executed as a regular non-privileged user
MySQL: Allow root remote access step by step instructions
Even after configuring MySQL to allow remote connections to the root account, you still need to allow connections to MySQL through the Linux firewall and make sure that MySQL is bound to an accessible interface. If you have not already configured those aspects, first see our guide on MySQL: Allow remote connections and then come back.
- To allow remote connections to the root account in MySQL, you should execute the
mysql_secure_installationcommand. Normally you run this command when first setting up MySQL, but it can be run again at any point if you need to reset the root account password or allow remote connections to the account.
$ sudo mysql_secure_installation
- Follow the prompts until you reach one that asks
Disallow root login remotely?and on this prompt, simply enter
- Once you finish going through the rest of the prompts, you will be able to access your MySQL server from remote systems using the root account. Of course, this is assuming that your firewall is correctly configured and your MySQL server (port 3306 by default) is already accessible over the internet.
- If this does not work for you, you can try editing the
mysql.userentry for root directly.
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost'; mysql> UPDATE mysql.user SET host='%' WHERE user='root';
And then restart MySQL:
$ sudo systemctl restart mysql
In this tutorial, we saw how to allow remote access to the root account in MySQL. This is a simple setting to configure inside of the
mysql_secure_installation prompts, which everyone is recommended to run through upon initial installation of MySQL server on Linux.