Langkah Install MySQL
1. Update repositori
sudo apt update sudo apt upgrade -y
2. Install MySQL Server
sudo apt install mysql-server -y
3. Cek apakah service MySQL sudah berjalan
sudo systemctl status mysql
Jika berjalan maka outputnya seperti ini:
</pre><pre>mysql.service - MySQL Community Server Loaded: loaded (/usr/lib/systemd/system/mysql.service; enabled; preset: enabled) Active: active (running) since Fri 2025-10-17 05:38:46 UTC; 29s ago Process: 23508 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=0/SUCCESS) Main PID: 23517 (mysqld) Status: "Server is operational" Tasks: 38 (limit: 8091) Memory: 363.7M (peak: 377.9M) CPU: 1.480s CGroup: /system.slice/mysql.service └─23517 /usr/sbin/mysqld Oct 17 05:38:45 homeserver systemd[1]: Starting mysql.service - MySQL Community Server... Oct 17 05:38:46 homeserver systemd[1]: Started mysql.service - MySQL Community Server.</pre>
4. Jalankan skrip untuk konfigurasi MySQL
sudo mysql_secure_installation
5. Login ke MySQL
sudo mysql -u root -p
Jika root belum ada passwordnya, set password
ALTER USER 'root'@'localhost' IDENTIFIED WITH caching_sha2_password BY 'gantipasswordanda'; FLUSH PRIVILEGES;
Setelah itu coba untuk login MySQL.
Enable Remote Access
Jika anda ingin akses MySQL dari luar komputer, maka ikuti langkah berikut
1. Edit konfigurasi MySQL
sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf
2. Ganti bind-address
Ganti
bind-address = 127.0.0.1
menjadi
bind-address = 0.0.0.0
3. Restart MySQL
sudo systemctl restart mysql
4. Login ke MySQL lalu buat user baru dengan host %
CREATE USER 'namauser'@'%' IDENTIFIED BY 'passwordkuat'; GRANT ALL PRIVILEGES ON namadb.* TO 'namauser'@'%'; FLUSH PRIVILEGES;
Untuk melihat ketentuan password MySQL pakai ini:
SHOW VARIABLES LIKE 'validate_password%';
5. Buka port di firewall, Jangan buka port MySQL langsung ke internet tanpa VPN atau firewall khusus.
sudo ufw allow 3306/tcp