1. 程式人生 > >CentOS7 離線編譯安裝Mysql5.7

CentOS7 離線編譯安裝Mysql5.7

First

下載Mysql-5.7的rpm-bundle版本,並使用xftp或者flashftp等工具上傳到CentOS上

在這裡插入圖片描述

Second

tar xvf mysql-5.7.23-1.el7.x86_64.rpm-bundle.tar ,解壓後會有很多rpm包,如下所示

mysql-community-client-5.7.23-1.el7.x86_64.rpm
mysql-community-common-5.7.23-1.el7.x86_64.rpm
mysql-community-devel-5.7.23-1.el7.x86_64.rpm
mysql-community-embedded-5.7.23-1.el7.x86_64.rpm
mysql-community-embedded-compat-5.7.23-1.el7.x86_64.rpm
mysql-community-embedded-devel-5.7.23-1.el7.x86_64.rpm
mysql-community-libs-5.7.23-1.el7.x86_64.rpm
mysql-community-libs-compat-5.7.23-1.el7.x86_64.rpm
mysql-community-minimal-debuginfo-5.7.23-1.el7.x86_64.rpm
mysql-community-server-5.7.23-1.el7.x86_64.rpm
mysql-community-server-minimal-5.7.23-1.el7.x86_64.rpm
mysql-community-test-5.7.23-1.el7.x86_64.rpm

Third

rpm -ivh mysql-community-server-5.7.23-1.el7.x86_64.rpm --nodeps ,忽略依賴關係分別安裝上面的包,其中server和server-minimal衝突,只安裝server即可。安裝成果反應如下:

[[email protected] mysql57]# rpm -ivh mysql-community-server-5.7.23-1.el7.x86_64.rpm --nodeps
warning: mysql-community-server-5.7.23-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing..
. ################################# [100%] Updating / installing... 1:mysql-community-server-5.7.23-1.e################################# [100%] [[email protected] mysql57]# rpm -ivh mysql-community-client-5.7.23-1.el7.x86_64.rpm --nodeps warning: mysql-community-client-5.7.23-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY Preparing..
. ################################# [100%] Updating / installing... 1:mysql-community-client-5.7.23-1.e################################# [100%] [[email protected] mysql57]# rpm -ivh mysql-community-libs-5.7.23-1.el7.x86_64.rpm --nodeps warning: mysql-community-libs-5.7.23-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY Preparing... ################################# [100%] Updating / installing... 1:mysql-community-libs-5.7.23-1.el7################################# [100%] [[email protected] mysql57]# rpm -ivh mysql-community-libs-compat-5.7.23-1.el7.x86_64.rpm --nodeps warning: mysql-community-libs-compat-5.7.23-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY Preparing... ################################# [100%] Updating / installing... 1:mysql-community-libs-compat-5.7.2################################# [100%]

安裝後可以通過,rpm -q 包名來檢視是否安裝上了,這裡有關rpm的命令推薦一篇文章《centos7 RPM包之rpm命令》

[tips]安裝過程中,可能會遇到conflict 報錯,比如下面:

[[email protected] mysql57]# rpm -ivh mysql-community-server-5.7.23-1.el7.x86_64.rpm --nodeps
warning: mysql-community-server-5.7.23-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                          ################################# [100%]
 file /etc/my.cnf from install of mysql-community-server-5.7.23-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.52-1.el7.x86_64

這是提示你係統中原來的包和你現在安裝的包衝突了,那麼你需要先解除安裝掉原來的包yum -y remove mariadb-libs.x86_64,再來安裝現在的包

Four

初始化mysql,systemctl start mysqld,MySQL自動會在/var/log/mysqld.log中隨機生成一個[email protected]密碼,grep 'password' /var/log/mysqld.log,返回如下:

2018-10-18T05:30:58.336743Z 0 [Note] Shutting down plugin 'sha256_password'
2018-10-18T05:30:58.336749Z 0 [Note] Shutting down plugin 'mysql_native_password'
2018-10-18T05:31:28.958031Z 0 [Note] Shutting down plugin 'sha256_password'
2018-10-18T05:31:28.958043Z 0 [Note] Shutting down plugin 'mysql_native_password'
2018-10-18T05:41:37.082893Z 0 [Note] Shutting down plugin 'sha256_password'
2018-10-18T05:41:37.082900Z 0 [Note] Shutting down plugin 'mysql_native_password'
2018-10-18T05:48:59.273589Z 1 [Note] A temporary password is generated for [email protected]: gs<7CafauqzL

這裡我的隨機密碼為gs<7CafauqzL

[tips]這裡可能會出現沒有temporary password的情況,又可能是你的歷史殘留檔案導致MySQL以為已經初始化過了,所以rm -rf /var/lib/mysql,刪掉歷史檔案,重啟mysqld即可以初始化成功

Five

mysql -uroot -p ,使用隨機密碼登陸,首次登陸必須修改密碼,否則不能進行任何資料操作

mysql> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

此處提示,必須先重置密碼

Six

alter user [email protected] identified by ‘your pwd’

需要注意的是,這裡密碼必須為含有大小寫字母、符號和數字的組合,才可以重置成功