Remote Access to MySQL /MariaDB Database in Ubuntu 16.04



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/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                              = 127.0.0.1
To
bind-address                               = 0.0.0.0
Restart MySQL Server
 
sudo /etc/init.d/mysql restart
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 0.0.0.0:3306          0.0.0.0:*        LISTEN   
NOW we need to create user and privilege permissions from MySQL
sudo mysql -u root -p
To Create User and Privilege :
CREATE USER 'username'@'%' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON *.* TO 'username'@'%' WITH GRANT OPTION;
FLUSH PRIVILEGES;
Restart MySQL Server
 
sudo /etc/init.d/mysql restart
That’s All !
Selim Reza

Site Footer