How Do I Enable Remote Access To MySQL Database Server-Centos7

Introduction

Database is one of the important factors to run an application. Sometimes we use databases in our local machine to store data related to our application. But with time it may become an issue to our application. In this article we will discuss how to enable remote access to a MySQL database server.

Enable Remote Access

Note: For the explanation of this article we are using a CentOS 7 machine with MySQL installed.

  • Step 1: Edit the configuration file

Open the configuration file /etc/my.cnf and add the following line to it.

bind-address = 0.0.0.0

Note: we have added external ip address as 0.0.0.0 for troubleshooting purpose. You can use * or :: other than 0.0.0.0

  • Step 2: Open 3306 port

Assuming you’ve configured a firewall on your database server, you need to open port 3306, MySQL default port

firewall-cmd --permanent --add-port=3306/tcp
firewall-cmd --reload

Note: By opening the port 3306, anyone will be able to access your MySQL server.

  • Step 3: Restart the MySQL service

Following command will restart the MySQL server in your CentOS 7 machine

systemctl restart mysqld

Verify the accessibility

You can verify whether your MySQL server can be reached from another machine with the following command

mysql -u user -h ip -p

Note:Replace the user with database user and ip with database server IP.

If it is success it confirms that remote access to MySQL server.

Related Articles