// Security in MySQL

MySQL Security Hardening

ปฏิบัติตามคำแนะนำเหล่านี้เพื่อความปลอดภัย 75% — Introduction, Access Control, Encryption และ Best Practices

Introduction

MySQL กลายเป็นฐานข้อมูลโอเพนซอร์สที่ได้รับความนิยมมากที่สุดในโลก เนื่องจากประสิทธิภาพสูง เชื่อถือได้ และง่ายต่อการใช้งาน ถูกใช้งานโดย Yahoo!, Alcatel-Lucent, Google, Nokia, YouTube และองค์กรชั้นนำอื่นๆ อย่างไรก็ตาม ความปลอดภัยของ MySQL มักถูกมองข้ามในการ Setup เริ่มต้น

// Security Checklist

MySQL Security Hardening Checklist

🔐
Secure Installation
รัน mysql_secure_installation ทันทีหลัง Install เพื่อ Set Root Password, ลบ Anonymous User และ Test Database
👤
User Privilege Management
สร้าง User ที่มี Privilege น้อยที่สุดที่จำเป็น (Principle of Least Privilege) ห้ามใช้ root สำหรับ Application
🌐
Network Security
Bind MySQL เฉพาะ IP ที่จำเป็น ปิด Remote Root Login ใช้ Firewall จำกัด Port 3306
🔒
SSL/TLS Encryption
เปิดใช้งาน SSL/TLS สำหรับ Connection ทั้งหมด โดยเฉพาะ Connection จาก Application Server
📋
Audit Logging
เปิดใช้งาน General Log หรือ MySQL Enterprise Audit เพื่อบันทึกกิจกรรมบน Database
🛡️
SQL Injection Prevention
ใช้ Prepared Statements เสมอ ห้าม String Concatenation ใน Query และ Validate Input ทุกตัว
// Hardening Commands

คำสั่ง Hardening ที่ควรทำทันที

-- 1. ลบ Anonymous Users DELETE FROM mysql.user WHERE User = ''; -- 2. ลบ Remote Root Access DELETE FROM mysql.user WHERE User = 'root' AND Host != 'localhost'; -- 3. ลบ Test Database DROP DATABASE IF EXISTS test; -- 4. สร้าง Application User ที่มี Minimal Privilege CREATE USER 'appuser'@'192.168.1.%' IDENTIFIED BY 'StrongPassword123!'; GRANT SELECT, INSERT, UPDATE, DELETE ON myapp.* TO 'appuser'@'192.168.1.%'; -- 5. Reload Privileges FLUSH PRIVILEGES;
// my.cnf Security

Security Settings ใน my.cnf

# /etc/mysql/my.cnf [mysqld] bind-address = 127.0.0.1 # Listen on localhost only local-infile = 0 # Disable LOAD DATA LOCAL skip-symbolic-links # Prevent symlink attacks secure-file-priv = /tmp # Restrict file operations ssl-ca = /etc/mysql/ssl/ca.pem ssl-cert = /etc/mysql/ssl/server-cert.pem ssl-key = /etc/mysql/ssl/server-key.pem
ต้องการ Security Audit?
ทีมผู้เชี่ยวชาญของเราพร้อม Audit ความปลอดภัยของ MySQL ของคุณและช่วย Harden ระบบ