Tips - Allow Remote connections to mySQL Database Server

Tips - Allow Remote connections to mySQL Database Server

In this Tips, we will go through the steps necessary to allow remote connections to a mySQL server. The same instructions can be apply for MariaDB.
Mika Baumeister©

By default, the mySQL allow connections only from localhost (, which means it can be accessed only by applications running on the same host.

However, in some situations, it is necessary to access the mySQL server from remote location. For example, when you want to connect to the remote mySQL server from your local system, or when using a multi-server deployment where the application is running on a different machine from the database server. One option would be to access the mySQL server through SSH Tunnel and another is to configure the mySQL server to accept remote connections.

Test on Debian 10 (buster) and mySQL v10.3.2.2

Note that the port number used for accepting incoming TCP connections is the same for every IP address listed in the –bind-address option.

  1. in /etc/mysql/mariadb.conf.d/50-server.cnf change line bind-address = to bind-address = The address allow all. If there is a line containing skip-networking, delete it or comment it out by adding # at the beginning of the line.
     bind-address =
  2. On mySQL server host :
     sudo mysql --user=root mysql
     GRANT ALL ON <database_name>.* TO <user_name>@<ip_address> IDENTIFIED BY <user_password>;


    • <database_name> is the name of the database that the user will connect to.
    • <user_name> is the name od the mySQL user.
    • <ip_address> is the IP address from which the user will connect. Use % to allow the user to connect from any IP address.
    • <user_password> is the user password.

    ie. <ip_address> : 192.168.% for allow the range of IP to or % for allow all IP

  3. Restart mysqld
     sudo systemctl restart mysqld
  4. Configuring Firewall The last step is to configure your firewall to allow traffic on port 3306 (mySQL default port) from the remote machines.
    • If you are using iptables as your firewall, the command bellow will allow access from private IP to the mySQL port.
       # Block all connections to 3306 except for localhost and all private IPs
       /sbin/iptables -A INPUT -p tcp --dport 3306 ! -s -j DROP
       /sbin/iptables -A INPUT -p tcp --dport 3306 ! -s -j DROP
       /sbin/iptables -A INPUT -p tcp --dport 3306 ! -s -j DROP
       /sbin/iptables -A INPUT -p tcp --dport 3306 ! -s -j DROP
    • Save the settings:
       sudo /sbin/iptables-save

Since mySQL Server v8.0.13, It’s possible to set more than one specific eth interface. So if you have a server with addresses and, you can specify the binding like: bind-address=, With for eth0 and for eth1

Share on :