1 Steps for a Fresh Installation of MySQL
# wget https://dev.mysql.com/get/mysql57-community-release-el6-9.noarch.rpm
# yum localinstall mysql57-community-release-el6-9.noarch.rpm
以上步驟其實是把 MySQL Yum repository 添加到了系統的 repository list 里去了。ll /etc/yum.repos.d/ 命令可以查看。
檢查 MySQL Yum repository 有沒有添加成功:
# yum repolist enabled| grep "mysql.*-community.*"
可以看到很多 Mysql repository。
2 Selecting a Release Series
默認是安裝最新的(5.7),如果要修改,這一步可以修改。詳見文檔。
3 Installing MySQL
# yum install mysql-community-server
默認會寫一個文件到 /etc/my.cnf,即 Mysql 的配置文件。
以上安裝命令還會安裝一下相關的組件,比如 mysql-community-client,詳見文檔。
4 Starting the MySQL Server
# service mysqld start
這里不太明白為什么啟動命令不是 service mysqld start。
查看運行狀態:
# service mysqld status
注意:Mysql5.7 不像5.6及以前的版本,5.6及以前的版本,默認的 root 賬戶密碼是空,但是 Mysql5.7 會設置 root 賬戶一個隨機密碼,并且存儲到 error log file,使用以下命令查看:
# grep 'temporary password' /var/log/mysqld.log
盡早修改默認的隨機密碼!步驟如下:
# mysql -uroot -p
# ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!';
說明:因為默認安裝并啟用了validate_password plugin,所以要求密碼:至少包含一個大寫、一個小寫、一個數字、一個特殊字符、至少8位。
5 Securing the MySQL Installation
不必多說,一個類似于安全向導的軟件,用于進行一些比如 root password 的設置操作:
# mysql_secure_installation
6 Installing Additional MySQL Products and Components with Yum
安裝額外的組件。詳見文檔。
7 其他安裝方式
其他很常見的就是自行下載 rpm 安裝包然后 rpm -ivh xxx.rpm 安裝方式了。總的來說,rpm 方式安裝自主性比較大一些,但是要自己先安裝依賴。這位博主的博客挺全的:《Linux 安裝 MySQL 以及 一些常見問題解決方案》。這里就不多說了。
8 相關文檔