Configure Remote Access to MySQL / MariaDB Databases

programming 3173456 640

This brief tutorial shows students and new users how to configure remote access to MySQL or MariaDB database servers on Ubuntu 17.04 | 17.10 systems. When configured correctly, you will be able to connect to the database servers from a remote system on the same network.

If the server is connected directory to the Internet, you may able able to access it from anywhere around the world where Internet access is available. however, opening up your database servers directly to the internet is not recommended.

In our next post, we’ll update this tutorial to show you how to enable secure the connection to the database server via SSL so that no one can intercept the communications and analyze the data between the server and the client computers.

When you’re ready to setup remote database access, please continue below.

By default, MySQL or MariaDB only listens for connections from the localhost. All remote access to the server is denied by default. To enable remote access, run the commands below to open MySQL/MariaDB configuration file.

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

on MariaDB server, the file may live below

sudo nano /etc/mysql/mariadb.conf.d/50-server.cnf

Then make the below change below from:

bind-address                              =


bind-address                               =

After making the change above, save the file and run the commands below to restart the server.

sudo systemctl restart mysql.service
sudo systemctl restart mariadb.service

To verify that the change happens, run the commands below

sudo netstat -anp | grep 3306

and you should find the result that looks like the one below

tcp       0      0*        LISTEN         3213/mysqld

Now the server is setup to listen to all IP addresses but individual IP needs to be explicitly configure to connect to a database.

To enable a client to connect to a database, you must grant access to the remote server.

For example, if you wish for a client computer with IP address to connect to a database called wpdatabase as user wpuser, then run the commands below after logging onto the database server.

GRANT ALL ON wpdatabase.* TO 'wpuser@' IDENTIFIED BY 'new password here';

After running the commands above, you should be able to access the server from the client computer with that assigned IP.

To connect to the server from the IP, run the commands below

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

That’s it! You’ve successfully configured a remote access to MySQL/MariaDB database server.

You may want to open Ubuntu Firewall to allow IP address to connect on port 3306.

sudo ufw allow from to any port 3306


This post shows students and new users how to connect remotely to MySQL or MariaDB database server. When configured correctly, systems that are granted access to defined databases should be allowed.




  2. That finally helped me, even the MariaDB website couldn’t help me that fast!

  3. Thank you, thank you very much… I was trying to interface MySQL installed in Google’s Compute Engine, and their documentation was pointing to the wrong configuration file…

  4. Hi,
    What does bind-address do? If we write our server’s IP address in bind-address and try to connect that server from remote server would it work?

  5. Hello,
    In “sudo mysql -uroot -pdatabaseuser_password -h server hostname or IP address” shouldn’t you write -u wpuser or -uwpuser instead of -uroot as it has access by remote server?

  6. Thanks bro!

  7. Thank you!

  8. Thanks very much! Is there a way to allow any IP into the database as an authorized user?

  9. Thanks….


  10. thanks you

  11. At last i could access my MariaDB on my Raspberry remotely using DBeaver ! Really, thanks a lot !

  12. A lot of thanks. Very useful.

  13. Tree days I was googling for this problem. This site finally solved the problem. Many many thanks.

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.