本文詳細記錄在 Linux/UNIX 環境下,從原始碼編譯安裝 MySQL 3.22.25 的完整流程,包含目錄規劃、權限設定、資料庫初始化、啟動與安全性設定。
# cd /usr/src
# tar -zvxf mysql-3.22.25-pc-linux-gnu-i686.tar.gz
# cd mysql-3.22.25-pc-linux-gnu-i686
# ./configure --prefix=/usr/local/mysql
# make
# make install
--prefix:指定安裝目標目錄,建議獨立目錄方便日後管理。# scripts/mysql_install_db
此步驟會在 /usr/local/mysql/var/ 建立兩個資料庫:
注意: 若曾安裝過 MySQL,舊資料庫已存在則無需重複執行。
# cd /usr/local/mysql/bin
# ./safe_mysqld &
若需開機自啟,將上述指令加入 /etc/rc.d/rc.local。
預設 root 無密碼,極度危險。請立即設定密碼:
# ./mysqladmin -u root password '新密碼'
$ ./mysql -u root # 應被拒絕
ERROR 1045: Access denied for user: 'root@localhost' (Using password: NO)
# ./mysql -u root -p # 應提示輸入密碼
Password: ********
Welcome to the MySQL monitor...
重要: 即使是系統 root 用戶,未加 -p 參數同樣會被拒絕,確保密碼驗證機制有效。
| 操作 | 指令 |
|---|---|
| 啟動服務 | |
| 停止服務 | |
| 帶密碼停止 |
將啟動指令加入 /etc/rc.local:
/bin/sh -c 'cd /usr/local/mysql ; ./bin/safe_mysqld &'
mysql 用戶。mysql 權限資料庫。