以前安裝Mysql都是要自己去網(wǎng)上選擇一個(gè)特定版本,然后再下載到服務(wù)器安裝,而且不同版本的相關(guān)命令也有所不同,學(xué)習(xí)記憶成本也非常高。現(xiàn)在官網(wǎng)可以通過安裝yum的依賴庫(kù)自由選擇安裝,非常的方便,今天來分享下。
- Adding the MySQL Yum Repository
sudo rpm -Uvh mysql57-community-release-el6-n.noarch.rpm
- Selecting a Release Series
yum repolist all | grep mysql
通過這個(gè)命令可以看到不同版本的默認(rèn)啟用情況,然后我們可以選擇自己的需要的版本,如果需要變更,需要修改/etc/yum.repos.d/mysql-community.repo的文件。
[mysql56-community]
name=MySQL 5.6 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.6-community/el/6/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
例如需要啟動(dòng)Mysql5.6,則將5.7的enabled=0,將5.6的enabled=1即可。修改完后確認(rèn)最終版本:
yum repolist enabled | grep mysql
- Installing MySQL
sudo yum install mysql-community-server
- Starting the MySQL Server
Start the MySQL server with the following command:
shell> sudo service mysqld start
For EL7-based platforms, this is the preferred command:
shell> sudo systemctl start mysqld.service
You can check the status of the MySQL server with the following command:
shell> sudo service mysqld status
For EL7-based platforms, this is the preferred command:
shell> sudo systemctl status mysqld.service
查看啟動(dòng)后的初始密碼:
sudo grep 'temporary password' /var/log/mysqld.log
最后通過初試密碼登錄并且修改root的密碼:
mysql -uroot -p
ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!';
大家喜歡可以訪問我的個(gè)人網(wǎng)站:http://www.yingminxing.com
如有疑問,歡迎溝通交流:QQ:370399195, 微信:yingminxing1988