How to allow remote access to MySQL/MariaDB
--
Set database user and password
mysql> grant all on *.* to username@localhost identified by ‘password’;
mysql> flush privileges;
To database:
mysql> create database databasename;
mysql> grant all on databasename.* to username@localhost identified by ‘password’;
mysql> flush privileges;
Remote access
Open config mysql file (unix):
$ sudo nano /etc/mysql/my.cnf
change lines:
bind-address = 127.0.0.1 > bind-address = 0.0.0.0
skip-networking > #skip-networking
Create user and password
mysql> CREATE USER ‘username’@’%’ IDENTIFIED BY ‘password’;
mysql> ON databasename.*
mysql> TO ‘username’@’%’
mysql> IDENTIFIED BY ‘newpassword’;
mysql> flush privileges;
Full access remote
mysql> CREATE USER ‘username’@’%’
mysql> IDENTIFIED BY ‘password’;
mysql> GRANT ALL ON *.* TO ‘username’@’%’;
mysql> flush privileges;
or
mysql> GRANT ALL PRIVILEGES ON *.* TO ‘username’@’%’
mysql> IDENTIFIED BY ‘password’
mysql> WITH GRANT OPTION;
mysql> flush privileges;
Restart
CentOS
$ sudo systemctl restart mysql
Fedora
$ service mysqld restart
Debian/Ubuntu
$ sudo service mysql restart
If your service is named “mysqld”, try this:
$ sudo /etc/init.d/mysql restart