安裝環境
[root@juny-18 ~]# cat /etc/redhat-release
CentOS Linux release 7.4.1708 (Core)
網絡yum源已經配好
檢查系統是否自帶有MySQL
[root@juny-18 ~]# yum list installed | grep mysql
如果有就用下面這命令來刪除
Yum remove -y (安裝包名)
第一步 下載yum庫
[root@juny-18 ~]# wget //dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
--2017-11-01 23:33:57-- //dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
正在解析主機 dev.mysql.com (dev.mysql.com)... 137.254.60.11
正在連接 dev.mysql.com (dev.mysql.com)|137.254.60.11|:80... 已連接。
中間有省略下載信息
正在保存至: "mysql57-community-release-el7-8.noarch.rpm"
100%[===========================================================================>] 9,116 --.-K/s 用時 0s
2017-11-01 23:35:29 (84.3 MB/s) - 已保存 "mysql57-community-release-el7-8.noarch.rpm" [9116/9116])
安裝MySQL的yum源
[root@juny-18 ~]# yum localinstall mysql57-community-release-el7-8.noarch.rpm
已加載插件:fastestmirror, langpacks
正在檢查 mysql57-community-release-el7-8.noarch.rpm: mysql57-community-release-el7-8.noarch
mysql57-community-release-el7-8.noarch.rpm 將被安裝
正在解決依賴關係
There are unfinished transactions remaining. You might consider running yum-complete-transaction, or "yum-complete-transaction --cleanup-only" and "yum history redo last", first to finish them. If those don't work you'll have to try removing/installing packages by hand (maybe package-cleanup can help).
--> 正在檢查事務
---> 軟件包 mysql57-community-release.noarch.0.el7-8 將被 安裝
--> 解決依賴關係完成
中間有省略下載信息
正在安裝 : mysql57-community-release-el7-8.noarch 1/1
驗證中 : mysql57-community-release-el7-8.noarch 1/1
已安裝:
mysql57-community-release.noarch 0:el7-8
完畢!
檢查MySQL源的安裝是否成功
[root@juny-18 ~]# yum repolist enabled | grep "mysql.*-community.*"
mysql-connectors-community/x86_64 MySQL Connectors Community 42
mysql-tools-community/x86_64 MySQL Tools Community 51
mysql57-community/x86_64 MySQL 5.7 Community Server 227
修改MySQL的yum源
修改前
修改後
第二步 開始安裝MySQL5.7數據庫
[root@juny-18 ~]# yum install mysql-community-server -y
正在解決依賴關係
There are unfinished transactions remaining. You might consider running yum-complete-transaction, or "yum-complete-transaction --cleanup-only" and "yum history redo last", first to finish them. If those don't work you'll have to try removing/installing packages by hand (maybe package-cleanup can help).
--> 正在檢查事務
---> 軟件包 mysql-community-server.x86_64.0.5.7.20-1.el7 將被 安裝
--> 正在處理依賴關係 mysql-community-common(x86-64) = 5.7.20-1.el7,它被軟件包 mysql-community-server-5.7.20-1.el7.x86_64 需要
--> 正在處理依賴關係 mysql-community-client(x86-64) >= 5.7.9,它被軟件包 mysql-community-server-5.7.20-1.el7.x86_64 需要
--> 正在檢查事務
---> 軟件包 mysql-community-client.x86_64.0.5.7.20-1.el7 將被 安裝
--> 正在處理依賴關係 mysql-community-libs(x86-64) >= 5.7.9,它被軟件包 mysql-community-client-5.7.20-1.el7.x86_64 需要
---> 軟件包 mysql-community-common.x86_64.0.5.7.20-1.el7 將被 安裝
--> 正在檢查事務
---> 軟件包 mariadb-libs.x86_64.1.5.5.52-1.el7 將被 取代
--> 正在處理依賴關係 libmysqlclient.so.18()(64bit),它被軟件包 2:postfix-2.10.1-6.el7.x86_64 需要
--> 正在處理依賴關係 libmysqlclient.so.18(libmysqlclient_18)(64bit),它被軟件包 2:postfix-2.10.1-6.el7.x86_64 需要
---> 軟件包 mysql-community-libs.x86_64.0.5.7.20-1.el7 將被 捨棄
--> 正在檢查事務
---> 軟件包 mysql-community-libs-compat.x86_64.0.5.7.20-1.el7 將被 捨棄
--> 解決依賴關係完成
依賴關係解決
中間有省略下載信息
事務概要
已安裝:
mysql-community-libs.x86_64 0:5.7.20-1.el7 mysql-community-libs-compat.x86_64 0:5.7.20-1.el7
mysql-community-server.x86_64 0:5.7.20-1.el7
作為依賴被安裝:
mysql-community-client.x86_64 0:5.7.20-1.el7 mysql-community-common.x86_64 0:5.7.20-1.el7
替代:
mariadb-libs.x86_64 1:5.5.52-1.el7
完畢!
第三步、啟動MySQL
[root@juny-18 ~]# systemctl start mysqld
獲取臨時密碼
進入mysql
[root@juny-18 ~]# mysql -uroot -pfjw_qP%V0lp#
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.20
Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
修改密碼
mysql> set password for 'root'@'localhost'=password('你的密碼');
設置開機啟動
[root@juny-18 ~]# systemctl enable mysqld
[root@juny-18 ~]# systemctl daemon-reload
一切結束