Linux

How to Create a Remote Root User in MySQL 5.7

A complete guide on how to enable remote access for the root user or create a new remote user in MySQL 5.7. This tutorial covers granting privileges, updating the bind-address configuration, opening port 3306, and testing remote connections safely. Ideal for anyone who needs MySQL access from external applications or management tools.

Remote access to MySQL is disabled by default for security reasons. If you need to connect to your MySQL 5.7 server from an external machine—using tools like MySQL Workbench, DBeaver, or another service—here is a full step-by-step guide.

1. Log in to MySQL

Start by accessing your database from the server terminal:

mysql -u root -p

2. Check whether the root user already allows remote access

Run:

SELECT Host, User FROM mysql.user WHERE User = 'root';

If you see Host = localhost, it means the root account can only log in locally.

3. Allow remote access for the root user

Option 1: Modify the existing root user (not recommended for production)

UPDATE mysql.user
SET Host='%'
WHERE User='root' AND Host='localhost';
FLUSH PRIVILEGES;

Option 2: Create a dedicated remote user (recommended)

This option is safer and follows best practices.

CREATE USER 'root'@'%' IDENTIFIED BY 'StrongPasswordHere';
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;
FLUSH PRIVILEGES;

4. Update MySQL configuration to listen on all interfaces

Edit the MySQL configuration file:

sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf

Find the line:

bind-address = 127.0.0.1

Change it to:

bind-address = 0.0.0.0

Restart MySQL:

sudo service mysql restart

 

5. Open port 3306 on your firewall

UFW (Ubuntu)

sudo ufw allow 3306

Firewalld (CentOS/RHEL)

sudo firewall-cmd --zone=public --add-port=3306/tcp --permanent
sudo firewall-cmd --reload

 

 

Security recommendations

  • Avoid enabling remote access for the root account in production.

  • Use strong passwords.

  • Restrict external access to specific IP addresses, for example:

CREATE USER 'root'@'123.456.789.10' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON *.* TO 'root'@'123.456.789.10';
  • Consider using SSH tunnels or VPN for safer connections.

Thanks for visit my website