ติดตั้ง MariaDB บน Ubuntu 18.04


Install MariaDB server

$ sudo apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8
$ sudo add-apt-repository 'deb [arch=amd64,arm64,ppc64el] http://ftp.utexas.edu/mariadb/repo/10.3/ubuntu bionic main'
$ sudo apt-get update
$ sudo apt-get install mariadb-server -y
$ mysql -V

Set secure

$ sudo mysql_secure_installation
  • Enter current password for root (enter for none): Just press the Enter
  • Set root password? [Y/n]: Y
  • New password: Enter password
  • Re-enter new password: Repeat password
  • Remove anonymous users? [Y/n]: Y
  • Disallow root login remotely? [Y/n]: Y
  • Remove test database and access to it? [Y/n]: Y
  • Reload privilege tables now? [Y/n]: Y

Allow All host

$ sudo vi /etc/mysql/mariadb.conf.d/50-server.cnf

edit or add bind-address 127.0.0.1 to 0.0.0.0

Restart

$ sudo systemctl restart mariadb.service

Check Port 3306 Allow

$ sudo netstat -anp | grep 3306

Access from Remote Clients

$ sudo mysql -u root
enter password: 
...
Grant All Privileges ON *.* to 'admin'@'%' Identified By 'password'; 

Try to connect

$ mysql -u database_user -p database_user_password -h database_server

Set Firewall

$ sudo ufw allow from <ip> to any port 3306

or

$ sudo ufw allow 3306/tcp

Not suggest because not allow all IP addresses not secure

June 19, 2020