MariaDB 是 MySQL 的社區分支,完全兼容 API 與命令列,採用 XtraDB 替代 InnoDB,目標成為 MySQL 直接替代品。本文提供 Ubuntu 14.04 上安裝、安全配置、遠程訪問啟用的完整步驟。
sudo apt-get install software-properties-common
sudo apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xcbcb082a1bb943db
sudo add-apt-repository 'deb https://sfo1.mirrors.digitalocean.com/mariadb/repo/10.0/ubuntu trusty main'
sudo apt-get update
sudo apt-get install mariadb-server
安裝過程會提示設定 root 密碼。
sudo apt-get update
sudo apt-get install mariadb-server
若報 Unable to locate package,執行:
sudo apt-get install python-software-properties
sudo add-apt-repository 'deb https://ftp.osuosl.org/pub/mariadb/repo/5.5/ubuntu quantal main'
sudo apt-get update
sudo apt-get install mariadb-server
安裝完成後必須執行:
sudo /usr/bin/mysql_secure_installation
交互式提示:
sudo nano /etc/mysql/my.cnfbind-address = 127.0.0.1,修改為 0.0.0.0(監聽所有介面)或具體業務伺服器 IPsudo service mysql restartmysql -u root -p
GRANT ALL PRIVILEGES ON *.* TO 'app_user'@'%' IDENTIFIED BY 'strong_password';
FLUSH PRIVILEGES;
安全提醒:生產環境務必配置防火牆(如 ufw allow from 10.0.0.0/8 to any port 3306)限制訪問來源。
# 啟動
sudo /etc/init.d/mysql start
# 或
sudo service mysql start
# 停止
sudo /etc/init.d/mysql stop
# 重啟
sudo /etc/init.d/mysql restart
# 狀態
sudo service mysql status
mysql -u root -p
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 40
Server version: 10.0.14-MariaDB-1~trusty-log mariadb.org binary distribution
MariaDB [(none)]> SHOW DATABASES;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
| 問題 | 解決 |
|---|---|
| 安裝卡在設定密碼畫面 | 終端編碼問題,試 export DEBIAN_FRONTEND=noninteractive 或重新安裝 |
| 遠程連線被拒 | 檢查 bind-address、防火牆、帳號 Host 欄位是否為 % |
| 中文亂碼 | 配置 character-set-server=utf8mb4 並重建資料庫/表 |
| 啟動失敗 | journalctl -u mysql 或 /var/log/mysql/error.log 查看具體錯誤 |
Ubuntu 14.04 部署 MariaDB 核心步驟:配置官方倉庫 → 安裝 mariadb-server → 執行 mysql_secure_installation → 按需開啟遠程訪問並配置防火牆。MariaDB 與 MySQL 操作習慣一致,遷移成本極低,適合追求開源社區維護、效能優化的團隊。