Enable Remote Access To MySQL / MariaDB Databases on Linux

By default, MySQL or MariaDB only listens for connections from the localhost. All remote access to the server is denied by default.

Step 1: To enable remote access, first find location of configuration file then run the commands below to open MySQL/MariaDB configuration file:

vi /etc/my.cnf

Depend on your OS and verion of MySQL / MariaDB you use, here are some locations:


You can find location by using this command:

find / -name my.cnf
find / -name *server.cnf
find / -name mysql.cnf

Step 2: You have to commented out (prefaced with hash (#) characters) the following lines:

    #bind-address = <some ip-address>

or you can use your server ip address (suppose: or

bind-address =

Step 3: restart MySQL / MariaDB server

systemctl restart mysql.service
systemctl restart mariadb.service

To verify that the change happens, run the commands below:

[root@tutorialspots ~]# netstat -anp | grep 3306
tcp6       0      0 :::3306                 :::*                    LISTEN      2884/mysqld

Step 4: open firewall (suppose remote address:

For iptables

[root@tutorialspots ~]# iptables -I INPUT -p udp -s --dport 3306 -j ACCEPT
[root@tutorialspots ~]# iptables -I INPUT -p tcp -s --dport 3306 -j ACCEPT
service iptables save

For firewalld

firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="" port protocol="tcp" port="3306" accept'
firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="" port protocol="udp" port="3306" accept'
sudo firewall-cmd --reload

Step 5: Connect to your MySQL / MariaDB server using root user

mysql -uroot -pdatabaseuser_password -h server hostname or IP address


[root@tutorialspots ~]#mysql -uroot -pMYROOTPASSWORD
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 61351084
Server version: 10.3.8-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]>

Step 6: For example, if you wish for a client computer with IP address (sometimes you must use hostname like sv.tutorialspots.com) to connect to a database called your_database_name as user your_user, then use this command:

GRANT ALL ON your_database_name.* TO 'your_user@' IDENTIFIED BY 'new password here';

enable remote access mysql mariadb

If you get error:

ERROR 1045 (28000): Access denied for user 'your_user'@'' (using password: YES)


GRANT ALL ON your_database_name.* TO 'your_user@' IDENTIFIED BY 'new password here';


CREATE USER 'your_user'@'' IDENTIFIED BY 'new password here'; 
grant all privileges on your_database_name.* to 'your_user'@'' with grant option;

Leave a Reply