Allow MySQL Remote Access in Ubuntu Server 16.04

In this tutorial we are going to learn how to allow remote access to the MySQL server in Ubuntu Server. For the tutorial I am using Ubuntu Server 16.04, But you can use this on any previous version of Ubuntu Linux.

Enable MySQL Server Remote Connection in Ubuntu

By default MySQL Server on Ubuntu run on the local interface, This means remote access to the MySQL Server is not Allowed. To enable remote connections to the MySQL Server we need to change value of the bind-address in the MySQL Configuration File.

First, Open the /etc/mysql/mysql.conf.d/mysqld.cnf file (/etc/mysql/my.cnf in Ubuntu 14.04 and earlier versions).

vim /etc/mysql/mysql.conf.d/mysqld.cnf

Under the [mysqld] Locate the Line,

bind-address            = 127.0.0.1

And change it to,

bind-address            = 0.0.0.0
Allow MySQL Remote Access in Ubuntu Server 16.04

Then, Restart the Ubuntu MysQL Server.

sudo service mysql restart

Now Ubuntu Server will allow remote access to the MySQL Server, But still you need to configure MySQL users to allow access from any host.

For example, when you create a MySQL user, you should allow access from any host.

CREATE USER 'username'@'%' IDENTIFIED BY 'password';

Or Allow from Specific IP Address,

CREATE USER 'username'@'192.168.1.100' IDENTIFIED BY 'password';

Or if you want to allow access for existing root to all databases and from any host

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'password';

Credits:
How to Allow MySQL Remote Access in Ubuntu Server 16.04

Leave a Reply