This page looks best with JavaScript enabled

Remote Access MySQL atau MariaDB

 ·  ☕ 1 min read

Remote Access MySQL/MariaDB

Konfigurasi

Konfigurasi MariaDB dengan merubah bind address dari 127.0.0.1 menjadi 0.0.0.0, kemudian restart service.

root@db:~# vim /etc/mysql/mariadb.conf.d/50-server.cnf

###
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
bind-address            = 0.0.0.0
###

root@db:~# systemctl restart mariadb

Cek ketersediaan port database:

root@db:~# netstat -tulpn | grep 3306
tcp        0      0 0.0.0.0:3306            0.0.0.0:*               LISTEN      3675/mysqld         

Buat user MySQL/MariaDB:

root@db:~# mysql -u root -p
Enter password: 
MariaDB [(none)]> use mysql

Database changed
MariaDB [mysql]> CREATE USER 'username'@'CLIENT_IP' IDENTIFIED BY 'password';
Query OK, 0 rows affected (0.00 sec)

Cek privileges dari user tersebut:

select * from user where user='username' \G

Privileges 1

User tersebut belum mendapatkan hak akses. Tambahkan hak akses terlebih dahulu pada user tersebut.

MariaDB [mysql]> GRANT ALL ON *.* to 'username'@'CLIENT_IP';
MariaDB [mysql]> update user SET Grant_priv='Y'  WHERE User = 'kilat';

Cek kembali privileges dari user tersebut.

select * from user where user='username' \G

Privileges 2

Sekarang user tersebut sudah mendapatkan hak akses penuh pada MySQL/MariaDB.

Percobaan

Tes koneksi ke database menggunakan telnet:

$ telnet IP_DATABASE 3306

Testing 1

Tes login ke MySQL/MariaDB:

$ mysql -h IP_DATABASE -u username -p

Testing 2

Selesai.

Share on

Iqbal
WRITTEN BY
Iqbal
I am just a man, not superhuman!