rhel7安裝mysql5.7
---------------------紅帽7----------------------
一、登入MySQL官網下載mysql
下載地址:https://dev.mysql.com/downloads/mysql/
因為有依賴關係,得下載下面五個包
mysql-community-client-5.7.24-1.el7.x86_64.rpm
mysql-community-common-5.7.24-1.el7.x86_64.rpm
mysql-community-devel-5.7.24-1.el7.x86_64.rpm
mysql-community-libs-5.7.24-1.el7.x86_64.rpm
mysql-community-server-5.7.24-1.el7.x86_64.rpm
二、檢視系統是否已經安裝了mysql沒有
程式碼 rpm -aq | grep mysql
Mariadb是rhel系統已經安裝好了的,需要解除安裝掉,安裝MySQL時可能有衝突,檢視Mariadb,程式碼 rpm -qa | grep mariadb
三、解除安裝Mariadb
用 rpm -e 解除安裝,因為有有依賴關係,末尾加上 --nodeps不顧依賴關係強制解除安裝
rpm -e 包名 --nodeps
四、建立安裝資料夾
[[email protected] Desktop]# mkdir -p /usr/local/mysql
五、將下載好的5個安裝包用 xshell 傳過去
[[email protected] Desktop]# cd /usr/local/mysql/
[[email protected] mysql]# ls
mysql-community-client-5.7.24-1.el7.x86_64.rpm
mysql-community-common-5.7.24-1.el7.x86_64.rpm
mysql-community-devel-5.7.24-1.el7.x86_64.rpm
mysql-community-libs-5.7.24-1.el7.x86_64.rpm
mysql-community-server-5.7.24-1.el7.x86_64.rpm
六、開始安裝,各個檔案是有依賴性的,必須按以下順序安裝
mysql-community-common-5.7.24-1.el7.x86_64.rpm
mysql-community-libs-5.7.24-1.el7.x86_64.rpm
mysql-community-client-5.7.24-1.el7.x86_64.rpm
imysql-community-server-5.7.24-1.el7.x86_64.rpm
mysql-community-devel-5.7.24-1.el7.x86_64.rpm
[[email protected] mysql]# rpm -ivh mysql-community-common-5.7.24-1.el7.x86_64.rpm warning: mysql-community-common-5.7.24-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY Preparing... ################################# [100%] Updating / installing... 1:mysql-community-common-5.7.24-1.e################################# [100%] [[email protected] mysql]# rpm -ivh mysql-community-libs-5.7.24-1.el7.x86_64.rpm warning: mysql-community-libs-5.7.24-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY Preparing... ################################# [100%] Updating / installing... 1:mysql-community-libs-5.7.24-1.el7################################# [100%] [[email protected] mysql]# rpm -ivh mysql-community-client-5.7.24-1.el7.x86_64.rpm warning: mysql-community-client-5.7.24-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY Preparing... ################################# [100%] Updating / installing... 1:mysql-community-client-5.7.24-1.e################################# [100%] [[email protected] mysql]# rpm -ivh mysql-community-server-5.7.24-1.el7.x86_64.rpm warning: mysql-community-server-5.7.24-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY Preparing... ################################# [100%] Updating / installing... 1:mysql-community-server-5.7.24-1.e################################# [100%] [[email protected] mysql]# rpm -ivh mysql-community-devel-5.7.24-1.el7.x86_64.rpm warning: mysql-community-devel-5.7.24-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY Preparing... ################################# [100%] Updating / installing... 1:mysql-community-devel-5.7.24-1.el################################# [100%]View Code
mysql安裝完畢後,是不會自動啟動的,但是第一次啟動後,以後開機都是自啟的,沒有第一次啟動之前,也是沒有密碼的。當你第一次啟動MySQL伺服器的時候,mysql自己就會自己做很多事情,其中之一重要的就是初始密碼
七、 啟動mysql服務
[[email protected] mysql]# systemctl start mysqld.service
[[email protected] mysql]# systemctl status mysqld.service
mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled)
Active: active (running) since Sat 2018-12-08 00:13:35 CST; 10s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Process: 4150 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
Process: 4072 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
Main PID: 4153 (mysqld)
CGroup: /system.slice/mysqld.service
└─4153 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mys...
Dec 08 00:13:35 localhost.localdomain systemd[1]: Started MySQL Server.
八、檢視初始密碼
啟動之後密碼就初始化好了,可以用 cat /var/log/mysqld.log 檢視
九、登入MySQL,登入進去是沒有許可權任何操作的,必須修改密碼
登入程式碼 mysql -u root -p 回車就讓你輸入密碼
[[email protected] mysql]# mysql -uroot -p Enter password: //輸入密碼
十、修改密碼
mysql> set password for 'root'@'localhost'='密碼' //密碼必須要符合要求,八位及以上,需要大小寫、數字和特殊字
mysql> set password for 'root'@'localhost'='qweQWE123<'; Query OK, 0 rows affected (0.00 sec)
到這裡就安裝完成了