Menu
📱 Lihat versi lengkap (non-AMP)
MySQL Debian Database Server

Instalasi MySQL 8.0 di Debian 12: Panduan Lengkap Server Production

Editor: Hendra WIjaya
Update: 3 February 2026
Baca: 3 menit

Instalasi MySQL 8.0 di Debian 12: Panduan Lengkap Server Production

Berdasarkan pengalaman mengelola infrastruktur database selama bertahun-tahun, Debian tetap menjadi pilihan favorit untuk server production karena stabilitasnya. Artikel ini membahas instalasi MySQL 8.0 di Debian 12 dengan konfigurasi optimal.

Kenapa Memilih Debian 12 untuk MySQL?

Debian 12 (Bookworm) menawarkan beberapa keuntungan:

  • Stabilitas yang teruji untuk long-term deployment
  • Security patch yang terupdate
  • Repository software yang matang
  • Resource usage yang efisien

Persiapan Sistem

1. Update Sistem Debian

sudo apt update
sudo apt upgrade -y
sudo apt full-upgrade -y

2. Install Dependencies

sudo apt install -y wget gnupg lsb-release ca-certificates curl

3. Verifikasi Arsitektur

dpkg --print-architecture

Proses Instalasi MySQL 8.0

1. Tambahkan MySQL APT Repository

Download dan install repository configuration:

cd /tmp
wget https://dev.mysql.com/get/mysql-apt-config_0.8.25-1_all.deb
sudo dpkg -i mysql-apt-config_0.8.25-1_all.deb

Pilih “MySQL Server & Cluster” dan pilih versi 8.0.

2. Update Repository

sudo apt update

3. Install MySQL Server

sudo apt install mysql-server -y

Proses instalasi akan menanyakan password root MySQL. Masukkan password yang kuat.

Konfigurasi Post-Instalasi

1. Secure Installation

Jalankan script keamanan:

sudo mysql_secure_installation

Ikuti petunjuk dengan pengaturan:

  • Password validation: STRONG
  • Change root password: Ya
  • Remove anonymous users: Ya
  • Disallow root remote login: Ya
  • Remove test database: Ya
  • Reload privileges: Ya

2. Konfigurasi File my.cnf

Edit file konfigurasi utama:

sudo nano /etc/mysql/my.cnf

Tambahkan konfigurasi global:

[client]
default-character-set = utf8mb4

[mysql]
default-character-set = utf8mb4

[mysqld]
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci

# InnoDB Settings
innodb_buffer_pool_size = 1G
innodb_log_file_size = 128M
innodb_flush_log_at_trx_commit = 2
innodb_file_per_table = 1

# Connection
max_connections = 100
max_allowed_packet = 64M

# Logging
log_error = /var/log/mysql/error.log
slow_query_log = 1
slow_query_log_file = /var/log/mysql/slow-queries.log
long_query_time = 2

# Security
local_infile = 0
skip-symbolic-links

3. Setup Log Directory

sudo mkdir -p /var/log/mysql
sudo chown mysql:mysql /var/log/mysql
sudo chmod 750 /var/log/mysql

Membuat Database dan User

1. Login sebagai Root

sudo mysql -u root -p

2. Buat Database Production

CREATE DATABASE production_db CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

3. Buat User dengan Hak Akses Terbatas

CREATE USER 'app_user'@'localhost' IDENTIFIED BY 'PasswordApp123!';
GRANT SELECT, INSERT, UPDATE, DELETE ON production_db.* TO 'app_user'@'localhost';
FLUSH PRIVILEGES;

4. Verifikasi User

SELECT User, Host FROM mysql.user;
SHOW GRANTS FOR 'app_user'@'localhost';

Optimasi Performance untuk Production

1. Monitoring Memory

Verifikasi penggunaan memory:

sudo mysql -e "SHOW VARIABLES LIKE 'innodb_buffer_pool_size';"

2. Konfigurasi Swappiness

Kurangi penggunaan swap untuk database:

echo "vm.swappiness = 1" | sudo tee -a /etc/sysctl.conf
sudo sysctl -p

3. Setting File Descriptor Limits

echo "mysql soft nofile 65535" | sudo tee -a /etc/security/limits.conf
echo "mysql hard nofile 65535" | sudo tee -a /etc/security/limits.conf

4. Optimasi I/O Scheduler

Untuk disk SSD:

echo 'ACTION=="add|change", KERNEL=="sd[a-z]", ATTR{queue/scheduler}="none"' | sudo tee /etc/udev/rules.d/60-ssd-scheduler.rules

Testing Koneksi dan Query

1. Test Koneksi Local

mysql -u app_user -p production_db -e "SELECT 1;"

2. Buat Tabel Test

USE production_db;

CREATE TABLE users (
    id INT AUTO_INCREMENT PRIMARY KEY,
    username VARCHAR(50) NOT NULL,
    email VARCHAR(100) NOT NULL,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    INDEX idx_email (email)
) ENGINE=InnoDB;

3. Insert Data Test

INSERT INTO users (username, email) VALUES 
('user1', 'user1@example.com'),
('user2', 'user2@example.com'),
('user3', 'user3@example.com');

Troubleshooting

Error: “Failed to start mysql.service”

Periksa log error:

sudo tail -f /var/log/mysql/error.log
sudo systemctl status mysql.service

Error: “Can’t connect to MySQL server”

Periksa socket dan port:

sudo netstat -tlnp | grep mysql
sudo ls -la /var/run/mysqld/

Reset Root Password

Jika lupa password root:

sudo systemctl stop mysql
sudo mysqld_safe --skip-grant-tables --skip-networking &
sudo mysql
FLUSH PRIVILEGES;
ALTER USER 'root'@'localhost' IDENTIFIED BY 'NewPassword123!';
EXIT;
sudo systemctl restart mysql

Setup Automated Backup

1. Install Tools

sudo apt install automysqlbackup

2. Konfigurasi Cron

sudo crontab -e

Tambahkan:

0 2 * * * /usr/sbin/automysqlbackup

Backup akan berjalan setiap jam 2 pagi.

Kesimpulan

Debian 12 dengan MySQL 8.0 memberikan fondasi database yang sangat stabil untuk production. Konfigurasi yang tepat sejak awal akan menghemat banyak waktu troubleshooting di kemudian hari.

Artikel Terkait

Bagikan:

Link Postingan: https://www.tirinfo.com/instalasi-mysql-8-debian-12-server/