Ralph

How To: Enable Remote MySQL Connections on Ubuntu Server

Introduction

user

Ralph

Ralph is a car enthusiast, blogger, author and teacher. In addition to being the founder of this website, Ralph is also a Linux Systems Administrator with 9 years+ experience who is also available for freelance or full-time work.


LATEST POSTS

The whole system that we live in drills into us… 23rd September, 2018

Canvas LMS: Install QTI Migration Tool 08th August, 2017

General

How To: Enable Remote MySQL Connections on Ubuntu Server

Posted on .

1. Identify public IP address:

$ curl ident.me

2. Edit /etc/mysql/my.cnf, replacing the value for bind-address, usually 127.0.0.1 with your public IP address derived above:

bind-address = 127.0.0.1

3. Type the following to enter the MySQL shell and provide your password:

mysql -u root -p

4. Grant remote access to the desired MySQL user with the following command, replacing ‘root’ with the desired user and ‘your-password’ with the user’s password:

mysql> GRANT ALL ON *.* TO 'root'@'%' IDENTIFIED BY 'your-password';
mysql> FLUSH PRIVILEGES;

5. Restart MySQL and verify it’s listening:

sudo service mysql restart && netstat -plnt | grep 'mysql'

Your output should look similar to this:

mysql stop/waiting
mysql start/running, process 16866
tcp        0      0 4.23.22.81:3306        0.0.0.0:*               LISTEN      16866/mysqld

6. You’re done. Now try connecting from a remote machine:

mysql -h 4.23.22.81 -u root -p

7. Profit!

profile

Ralph

Ralph is a car enthusiast, blogger, author and teacher. In addition to being the founder of this website, Ralph is also a Linux Systems Administrator with 9 years+ experience who is also available for freelance or full-time work.

Navigation