MySQL: Allow root remote access

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
Entering no on the disallow remote root login prompt
Entering no on the disallow remote root login prompt
Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Linux system
Software MySQL
Other Privileged access to your Linux system as root or via the sudo command.
Conventions # – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ – requires given linux commands to be executed as a regular non-privileged user

MySQL: Allow root remote access step by step instructions



Twitter icon Follow LinuxConfig.org on Twitter for the latest tips and tricks about Linux!

NOTE
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.
  1. To allow remote connections to the root account in MySQL, you should execute the mysql_secure_installation command. 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
    
  2. Follow the prompts until you reach one that asks Disallow root login remotely? and on this prompt, simply enter no.
  3. 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.
  4. If this does not work for you, you can try editing the mysql.user entry 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
    

Closing Thoughts

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.



Comments and Discussions
Linux Forum