此文參考官方文檔一步一步記錄安裝到正常運行全過程
安裝環(huán)境:centos7
mysql版本:8.0.35
安裝過程主要參考下面兩邊文章:
1.官方文檔
https://dev.mysql.com/doc/refman/8.0/en/linux-installation-yum-repo.html
2.linux yum安裝mysql8
安裝過程大概有以下幾步:
1.查找mysql源鏈接
2.安裝mysql源(倉庫)
3.安裝mysql服務(wù)
4.啟動mysql服務(wù)
5.獲取并修改密碼
6.防火墻放行、遠程登錄和設(shè)置
因為我的這個centos之前用寶塔裝過mysql5.6版本,所以走了一點彎路,過程也記錄下來了。如果也是同樣情況,建議一開始就卸載舊版本再安裝8.0版本。
另外,我避開下面的坑,又重新記錄了在一臺centosh上mysql8.0過程,可以參考下面我寫的另外一篇文章:
《在CentOS上用yum方式安裝MySQL8真實全過程記錄(順利版本)》
一、查找mysql源鏈接
(MySQL Yum Repository,找MySQL官方y(tǒng)um倉庫地址并下載)
根據(jù)官方文檔提示,進入到mysql yum倉庫的下載頁面(如下圖)
https://dev.mysql.com/downloads/repo/yum/
因為我的CentOS版本是7,所以選擇對應(yīng)的版本,點擊download進入下載頁面(如下圖)
提示注冊,不需要注冊,我們直接復(fù)制下面的下載地址即可。
復(fù)制到的地址為:
https://repo.mysql.com//mysql80-community-release-el7-11.noarch.rpm
二、安裝mysql源(倉庫)
[root@szaliyun ~]# yum localinstall https://repo.mysql.com//mysql80-community-release-el7-11.noarch.rpm
已加載插件:fastestmirror
mysql80-community-release-el7-11.noarch.rpm | 14 kB 00:00:00
正在檢查 /var/tmp/yum-root-hMU7pD/mysql80-community-release-el7-11.noarch.rpm: mysql80-community-release-el7-11.noarch
/var/tmp/yum-root-hMU7pD/mysql80-community-release-el7-11.noarch.rpm 將被安裝
正在解決依賴關(guān)系
--> 正在檢查事務(wù)
---> 軟件包 mysql80-community-release.noarch.0.el7-11 將被 安裝
--> 解決依賴關(guān)系完成
依賴關(guān)系解決
===============================================================================================================================================================================================
Package 架構(gòu) 版本 源 大小
===============================================================================================================================================================================================
正在安裝:
mysql80-community-release noarch el7-11 /mysql80-community-release-el7-11.noarch 17 k
事務(wù)概要
===============================================================================================================================================================================================
安裝 1 軟件包
總計:17 k
安裝大?。?7 k
Is this ok [y/d/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
正在安裝 : mysql80-community-release-el7-11.noarch 1/1
驗證中 : mysql80-community-release-el7-11.noarch 1/1
已安裝:
mysql80-community-release.noarch 0:el7-11
完畢!
過程中提問是否安裝,輸入y后回車。
三、安裝mysql服務(wù)
列出已啟用的包含 “mysql.-community.” 關(guān)鍵字的軟件包倉庫
[root@szaliyun ~]# yum repolist enabled
已加載插件:fastestmirror
Loading mirror speeds from cached hostfile
源標識 源名稱 狀態(tài)
base/7/x86_64 CentOS-7 10,070+2
epel/x86_64 Extra Packages for Enterprise Linux 7 - x86_64 13,788+2
extras/7/x86_64 CentOS-7 518
mysql-connectors-community/x86_64 MySQL Connectors Community 234
mysql-tools-community/x86_64 MySQL Tools Community 102
mysql80-community/x86_64 MySQL 8.0 Community Server 446
updates/7/x86_64 CentOS-7 5,359+8
repolist: 30,517
[root@szaliyun ~]# yum repolist enabled | grep "mysql.*-community.*"
mysql-connectors-community/x86_64 MySQL Connectors Community 234
mysql-tools-community/x86_64 MySQL Tools Community 102
mysql80-community/x86_64 MySQL 8.0 Community Server 446
[root@szaliyun ~]#
yum repolist enabled 用于列出已啟用的軟件包倉庫,grep “mysql.-community.” 用于過濾出包含 “mysql.-community.” 關(guān)鍵字的軟件包倉庫。
安裝
[root@szaliyun ~]# yum install mysql-community-server
已加載插件:fastestmirror
Loading mirror speeds from cached hostfile
base | 3.6 kB 00:00:00
epel | 4.7 kB 00:00:00
extras | 2.9 kB 00:00:00
mysql-connectors-community | 2.6 kB 00:00:00
mysql-tools-community | 2.6 kB 00:00:19
mysql80-community | 2.6 kB 00:00:04
updates | 2.9 kB 00:00:00
正在解決依賴關(guān)系
--> 正在檢查事務(wù)
---> 軟件包 mysql-community-server.x86_64.0.8.0.35-1.el7 將被 安裝
--> 正在處理依賴關(guān)系 mysql-community-common(x86-64) = 8.0.35-1.el7,它被軟件包 mysql-community-server-8.0.35-1.el7.x86_64 需要
--> 正在處理依賴關(guān)系 mysql-community-icu-data-files = 8.0.35-1.el7,它被軟件包 mysql-community-server-8.0.35-1.el7.x86_64 需要
--> 正在處理依賴關(guān)系 mysql-community-client(x86-64) >= 8.0.11,它被軟件包 mysql-community-server-8.0.35-1.el7.x86_64 需要
--> 正在檢查事務(wù)
---> 軟件包 mysql-community-client.x86_64.0.8.0.35-1.el7 將被 安裝
--> 正在處理依賴關(guān)系 mysql-community-client-plugins = 8.0.35-1.el7,它被軟件包 mysql-community-client-8.0.35-1.el7.x86_64 需要
--> 正在處理依賴關(guān)系 mysql-community-libs(x86-64) >= 8.0.11,它被軟件包 mysql-community-client-8.0.35-1.el7.x86_64 需要
---> 軟件包 mysql-community-common.x86_64.0.8.0.35-1.el7 將被 安裝
---> 軟件包 mysql-community-icu-data-files.x86_64.0.8.0.35-1.el7 將被 安裝
--> 正在檢查事務(wù)
---> 軟件包 mariadb-libs.x86_64.1.5.5.68-1.el7 將被 取代
--> 正在處理依賴關(guān)系 libmysqlclient.so.18()(64bit),它被軟件包 2:postfix-2.10.1-9.el7.x86_64 需要
--> 正在處理依賴關(guān)系 libmysqlclient.so.18(libmysqlclient_18)(64bit),它被軟件包 2:postfix-2.10.1-9.el7.x86_64 需要
---> 軟件包 mysql-community-client-plugins.x86_64.0.8.0.35-1.el7 將被 安裝
---> 軟件包 mysql-community-libs.x86_64.0.8.0.35-1.el7 將被 舍棄
--> 正在檢查事務(wù)
---> 軟件包 mysql-community-libs-compat.x86_64.0.8.0.35-1.el7 將被 舍棄
--> 解決依賴關(guān)系完成
依賴關(guān)系解決
===============================================================================================================================================================================================
Package 架構(gòu) 版本 源 大小
===============================================================================================================================================================================================
正在安裝:
mysql-community-libs x86_64 8.0.35-1.el7 mysql80-community 1.5 M
替換 mariadb-libs.x86_64 1:5.5.68-1.el7
mysql-community-libs-compat x86_64 8.0.35-1.el7 mysql80-community 669 k
替換 mariadb-libs.x86_64 1:5.5.68-1.el7
mysql-community-server x86_64 8.0.35-1.el7 mysql80-community 64 M
為依賴而安裝:
mysql-community-client x86_64 8.0.35-1.el7 mysql80-community 16 M
mysql-community-client-plugins x86_64 8.0.35-1.el7 mysql80-community 3.5 M
mysql-community-common x86_64 8.0.35-1.el7 mysql80-community 665 k
mysql-community-icu-data-files x86_64 8.0.35-1.el7 mysql80-community 2.2 M
事務(wù)概要
===============================================================================================================================================================================================
安裝 3 軟件包 (+4 依賴軟件包)
總下載量:89 M
Is this ok [y/d/N]: y
Downloading packages:
mysql-community-client-8.0.35- FAILED 0% [ ] 1.1 kB/s | 46 kB 23:13:17 ETA
http://repo.mysql.com/yum/mysql-8.0-community/el/7/x86_64/mysql-community-client-8.0.35-1.el7.x86_64.rpm: [Errno 12] Timeout on http://repo.mysql.com/yum/mysql-8.0-community/el/7/x86_64/mysql-community-client-8.0.35-1.el7.x86_64.rpm: (28, 'Operation too slow. Less than 1000 bytes/sec transferred the last 30 seconds')
正在嘗試其它鏡像。
mysql-community-client-plugins FAILED 0% [ ] 1.4 kB/s | 280 kB 18:15:11 ETA
http://repo.mysql.com/yum/mysql-8.0-community/el/7/x86_64/mysql-community-client-plugins-8.0.35-1.el7.x86_64.rpm: [Errno 12] Timeout on http://repo.mysql.com/yum/mysql-8.0-community/el/7/x86_64/mysql-community-client-plugins-8.0.35-1.el7.x86_64.rpm: (28, 'Operation too slow. Less than 1000 bytes/sec transferred the last 30 seconds')
正在嘗試其它鏡像。
mysql-community-common-8.0.35- FAILED 0% [ ] 2.1 B/s | 434 kB 12427:49:49 ETA
http://repo.mysql.com/yum/mysql-8.0-community/el/7/x86_64/mysql-community-common-8.0.35-1.el7.x86_64.rpm: [Errno 12] Timeout on http://repo.mysql.com/yum/mysql-8.0-community/el/7/x86_64/mysql-community-common-8.0.35-1.el7.x86_64.rpm: (28, 'Operation too slow. Less than 1000 bytes/sec transferred the last 30 seconds')
正在嘗試其它鏡像。
mysql-community-icu-data-files FAILED 0% [ ] 5.4 B/s | 68 kB 4752:59:45 ETA
http://repo.mysql.com/yum/mysql-8.0-community/el/7/x86_64/mysql-community-icu-data-files-8.0.35-1.el7.x86_64.rpm: [Errno 12] Timeout on http://repo.mysql.com/yum/mysql-8.0-community/el/7/x86_64/mysql-community-icu-data-files-8.0.35-1.el7.x86_64.rpm: (28, 'Operation too slow. Less than 1000 bytes/sec transferred the last 30 seconds')
正在嘗試其它鏡像。
mysql-community-libs-8.0.35-1. FAILED 0% [ ] 0.8 B/s | 184 kB 31857:32:53 ETA
http://repo.mysql.com/yum/mysql-8.0-community/el/7/x86_64/mysql-community-libs-8.0.35-1.el7.x86_64.rpm: [Errno 12] Timeout on http://repo.mysql.com/yum/mysql-8.0-community/el/7/x86_64/mysql-community-libs-8.0.35-1.el7.x86_64.rpm: (28, 'Operation too slow. Less than 1000 bytes/sec transferred the last 30 seconds')
正在嘗試其它鏡像。
mysql-community-libs-compat-8. FAILED 0% [ ] 9.6 B/s | 550 kB 2674:52:24 ETA
http://repo.mysql.com/yum/mysql-8.0-community/el/7/x86_64/mysql-community-libs-compat-8.0.35-1.el7.x86_64.rpm: [Errno 12] Timeout on http://repo.mysql.com/yum/mysql-8.0-community/el/7/x86_64/mysql-community-libs-compat-8.0.35-1.el7.x86_64.rpm: (28, 'Operation too slow. Less than 1000 bytes/sec transferred the last 30 seconds')
正在嘗試其它鏡像。
mysql-community-server-8.0.35- FAILED
http://repo.mysql.com/yum/mysql-8.0-community/el/7/x86_64/mysql-community-server-8.0.35-1.el7.x86_64.rpm: [Errno 12] Timeout on http://repo.mysql.com/yum/mysql-8.0-community/el/7/x86_64/mysql-community-server-8.0.35-1.el7.x86_64.rpm: (28, 'Operation too slow. Less than 1000 bytes/sec transferred the last 30 seconds')
正在嘗試其它鏡像。
mysql-community-client-8.0.35- FAILED 0% [- ] 5.6 B/s | 804 kB 4605:51:37 ETA
http://repo.mysql.com/yum/mysql-8.0-community/el/7/x86_64/mysql-community-client-8.0.35-1.el7.x86_64.rpm: [Errno 12] Timeout on http://repo.mysql.com/yum/mysql-8.0-community/el/7/x86_64/mysql-community-client-8.0.35-1.el7.x86_64.rpm: (28, 'Operation too slow. Less than 1000 bytes/sec transferred the last 30 seconds')
正在嘗試其它鏡像。
警告:/var/cache/yum/x86_64/7/mysql80-community/packages/mysql-community-client-plugins-8.0.35-1.el7.x86_64.rpm: 頭V4 RSA/SHA256 Signature, 密鑰 ID 3a79bd29: NOKEYkB/s | 3.3 MB 00:01:59 ETA
mysql-community-client-plugins-8.0.35-1.el7.x86_64.rpm 的公鑰尚未安裝
(1/7): mysql-community-client-plugins-8.0.35-1.el7.x86_64.rpm | 3.5 MB 00:00:02
(2/7): mysql-community-common-8.0.35-1.el7.x86_64.rpm | 665 kB 00:00:00
(3/7): mysql-community-icu-data-files-8.0.35-1.el7.x86_64.rpm | 2.2 MB 00:00:00
(4/7): mysql-community-libs-8.0.35-1.el7.x86_64.rpm | 1.5 MB 00:00:00
(5/7): mysql-community-libs-compat-8.0.35-1.el7.x86_64.rpm | 669 kB 00:00:00
(6/7): mysql-community-server-8.0.35-1.el7.x86_64.rpm | 64 MB 00:00:10
(7/7): mysql-community-client-8.0.35-1.el7.x86_64.rpm | 16 MB 00:00:02
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
總計 71 kB/s | 89 MB 00:21:14
從 file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2023 檢索密鑰
導(dǎo)入 GPG key 0xA8D3785C:
用戶ID : "MySQL Release Engineering <mysql-build@oss.oracle.com>"
指紋 : bca4 3417 c3b4 85dd 128e c6d4 b7b3 b788 a8d3 785c
軟件包 : mysql80-community-release-el7-11.noarch (@/mysql80-community-release-el7-11.noarch)
來自 : /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2023
是否繼續(xù)?[y/N]:從 file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2022 檢索密鑰
導(dǎo)入 GPG key 0x3A79BD29:
用戶ID : "MySQL Release Engineering <mysql-build@oss.oracle.com>"
指紋 : 859b e8d7 c586 f538 430b 19c2 467b 942d 3a79 bd29
軟件包 : mysql80-community-release-el7-11.noarch (@/mysql80-community-release-el7-11.noarch)
來自 : /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2022
是否繼續(xù)?[y/N]:y
從 file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql 檢索密鑰
導(dǎo)入 GPG key 0x5072E1F5:
用戶ID : "MySQL Release Engineering <mysql-build@oss.oracle.com>"
指紋 : a4a9 4068 76fc bd3c 4567 70c8 8c71 8d3b 5072 e1f5
軟件包 : mysql80-community-release-el7-11.noarch (@/mysql80-community-release-el7-11.noarch)
來自 : /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
是否繼續(xù)?[y/N]:y
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
正在安裝 : mysql-community-common-8.0.35-1.el7.x86_64 1/8
正在安裝 : mysql-community-client-plugins-8.0.35-1.el7.x86_64 2/8
正在安裝 : mysql-community-libs-8.0.35-1.el7.x86_64 3/8
正在安裝 : mysql-community-client-8.0.35-1.el7.x86_64 4/8
正在安裝 : mysql-community-icu-data-files-8.0.35-1.el7.x86_64 5/8
正在安裝 : mysql-community-server-8.0.35-1.el7.x86_64 6/8
warning: /etc/my.cnf created as /etc/my.cnf.rpmnew
正在安裝 : mysql-community-libs-compat-8.0.35-1.el7.x86_64 7/8
正在刪除 : 1:mariadb-libs-5.5.68-1.el7.x86_64 8/8
驗證中 : mysql-community-client-plugins-8.0.35-1.el7.x86_64 1/8
驗證中 : mysql-community-common-8.0.35-1.el7.x86_64 2/8
驗證中 : mysql-community-icu-data-files-8.0.35-1.el7.x86_64 3/8
驗證中 : mysql-community-libs-8.0.35-1.el7.x86_64 4/8
驗證中 : mysql-community-client-8.0.35-1.el7.x86_64 5/8
驗證中 : mysql-community-libs-compat-8.0.35-1.el7.x86_64 6/8
驗證中 : mysql-community-server-8.0.35-1.el7.x86_64 7/8
驗證中 : 1:mariadb-libs-5.5.68-1.el7.x86_64 8/8
已安裝:
mysql-community-libs.x86_64 0:8.0.35-1.el7 mysql-community-libs-compat.x86_64 0:8.0.35-1.el7 mysql-community-server.x86_64 0:8.0.35-1.el7
作為依賴被安裝:
mysql-community-client.x86_64 0:8.0.35-1.el7 mysql-community-client-plugins.x86_64 0:8.0.35-1.el7 mysql-community-common.x86_64 0:8.0.35-1.el7
mysql-community-icu-data-files.x86_64 0:8.0.35-1.el7
替代:
mariadb-libs.x86_64 1:5.5.68-1.el7
完畢!
[root@szaliyun ~]#
可以看到安裝并不順利,程序自動更換鏡像后安裝最終完成。
四、啟動mysql服務(wù)
[root@szaliyun ~]# systemctl status mysqld
啟動失敗,查日志
[root@szaliyun ~]# journalctl -xe | grep mysql
查到說redo log格式不對
10月 26 07:14:54 szaliyun mysqld[19819]: 2023-10-25T23:14:53.988237Z 1 [ERROR] [MY-013090] [InnoDB] Unsupported redo log format (v0). The redo log was created before MySQL 5.7.9
按網(wǎng)上查了一下,說是需要將ib_logfile0和ib_logfile1移走
于是查找并移走這兩個文件,重啟依舊報錯,說找不到目錄
Neither found #innodb_redo subdirectory, nor ib_logfile* files in /www/server/data/
嘗試了網(wǎng)上說的一些方法,也解決不了,估計是mysql5.7版本沒卸載導(dǎo)致8.0不能正常運行。
實在沒辦法就卸載重裝吧:
[root@szaliyun ~]# rpm -qa | grep -i mysql
bt-mysql56-5.6.50-1.el7.x86_64
mysql-community-libs-8.0.35-1.el7.x86_64
mysql-community-libs-compat-8.0.35-1.el7.x86_64
mysql-community-client-plugins-8.0.35-1.el7.x86_64
mysql-community-client-8.0.35-1.el7.x86_64
mysql-community-server-8.0.35-1.el7.x86_64
mysql80-community-release-el7-11.noarch
mysql-community-common-8.0.35-1.el7.x86_64
mysql-community-icu-data-files-8.0.35-1.el7.x86_64
[root@szaliyun ~]#
[root@szaliyun ~]# yum remove bt-mysql56-5.6.50-1.el7.x86_64
[root@szaliyun ~]# yum remove mysql-community-server-8.0.35-1.el7.x86_64
[root@szaliyun ~]# yum install mysql-community-server
啟動mysql,繼續(xù)報錯:
[root@szaliyun ~]# cat /var/log/mysqld.log
2023-10-29T08:28:10.584709Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.35) initializing of server in progress as process 21123
2023-10-29T08:28:10.589908Z 0 [ERROR] [MY-010457] [Server] --initialize specified but the data directory has files in it. Aborting.
2023-10-29T08:28:10.589953Z 0 [ERROR] [MY-013236] [Server] The designated data directory /var/lib/mysql/ is unusable. You can remove all files that the server added to it.
2023-10-29T08:28:10.590006Z 0 [ERROR] [MY-010119] [Server] Aborting
關(guān)鍵是這一條:2023-10-29T08:28:10.589953Z 0 [ERROR] [MY-013236] [Server] The designated data directory /var/lib/mysql/ is unusable. You can remove all files that the server added to it.
大概是說指定的這個目錄不可用,你可以刪除所有這些文件。做好備份后刪掉重新啟動。
[root@szaliyun lib]# cp -r mysql/ mysql231029back
[root@szaliyun lib]# cd mysql
[root@szaliyun mysql]# ls
auto.cnf binlog.index ca-key.pem ca.pem client-cert.pem client-key.pem #innodb_redo mysql-bin private_key.pem public_key.pem server-cert.pem server-key.pem
[root@szaliyun mysql]# rm -rf /var/lib/mysql/*
[root@szaliyun mysql]# ls
[root@szaliyun mysql]# systemctl start mysql
Failed to start mysql.service: Unit not found.
[root@szaliyun mysql]# systemctl start mysqld
[root@szaliyun mysql]#
[root@szaliyun mysql]# systemctl status mysqld
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: active (running) since 日 2023-10-29 16:46:32 CST; 6s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Process: 11202 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
Main PID: 11369 (mysqld)
Status: "Server is operational"
CGroup: /system.slice/mysqld.service
└─11369 /usr/sbin/mysqld
10月 29 16:46:26 szaliyun systemd[1]: Starting MySQL Server...
10月 29 16:46:32 szaliyun systemd[1]: Started MySQL Server.
[root@szaliyun mysql]#
啟動成功!
五、獲取并修改密碼
獲取臨時密碼
[root@szaliyun mysql]# grep 'temporary password' /var/log/mysqld.log
2023-10-29T08:46:29.090680Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: giAufyacf3</
[root@szaliyun mysql]#
然后嘗試登錄
[root@szaliyun /]# mysql -u root -p
-bash: mysql: 未找到命令
[root@szaliyun mysql]# which mysql
/usr/bin/which: no mysql in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin)
[root@szaliyun mysql]#
沒有找到mysql,經(jīng)過幾番測試,還是沒找到mysql的安裝目錄,最后GPT讓我重裝。
[root@szaliyun mysql]# rpm -qa | grep mysql
mysql-community-libs-8.0.35-1.el7.x86_64
mysql-community-libs-compat-8.0.35-1.el7.x86_64
mysql-community-server-8.0.35-1.el7.x86_64
mysql-community-client-plugins-8.0.35-1.el7.x86_64
mysql-community-client-8.0.35-1.el7.x86_64
mysql80-community-release-el7-11.noarch
mysql-community-common-8.0.35-1.el7.x86_64
mysql-community-icu-data-files-8.0.35-1.el7.x86_64
[root@szaliyun mysql]# yum reinstall mysql-community-client-8.0.35-1.el7.x86_64
重裝完之后就可以了
[root@szaliyun mysql]# which mysql
/usr/bin/mysql
然后就是修改密碼:
[root@szaliyun /]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 8.0.35
Copyright (c) 2000, 2023, Oracle and/or its affiliates.
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> ALTER USER 'root'@'localhost' IDENTIFIED BY 'New%Password4';
Query OK, 0 rows affected (0.15 sec)
mysql>
至此修改密碼完成。
六、防火墻放行、遠程登錄和設(shè)置
放開CentOS網(wǎng)絡(luò)端口
[root@szaliyun ~]# firewall-cmd --zone=public --add-port=3306/tcp --permanent
[root@szaliyun ~]# firewall-cmd --reload
然后再在硬件防火墻上放開(如果需要),如果是使用云服務(wù)器(例如阿里云),則在云供應(yīng)商的設(shè)置頁面放開3306端口。
然后在公網(wǎng)上telnet ip 3306,端口通了。
再使用SQLyog嘗試連接數(shù)據(jù)庫,顯示 :
出現(xiàn)這個Host is not allowed to connect to this MySQL server很常見,就是我現(xiàn)在要連接的ip沒有授權(quán)訪問,授權(quán)就好。
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> update user set host = '%' where user = 'root';
Query OK, 1 row affected (0.02 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.01 sec)
mysql>
繼續(xù)測試連接,報下面錯誤:
Plugin caching_sha2_password could not be loaded報錯
這是因為MYSQL8.0版使用了新的密碼機制。
為了方便,將密碼機制改為mysql_native_password(安全性降低了)
mysql> select Host,User,Plugin from mysql.user;
+-----------+------------------+-----------------------+
| Host | User | Plugin |
+-----------+------------------+-----------------------+
| % | root | caching_sha2_password |
| localhost | mysql.infoschema | caching_sha2_password |
| localhost | mysql.session | caching_sha2_password |
| localhost | mysql.sys | caching_sha2_password |
+-----------+------------------+-----------------------+
4 rows in set (0.00 sec)
mysql> alter user root@'%' identified with mysql_native_password by 'New#password2';
Query OK, 0 rows affected (0.00 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
mysql> select Host,User,Plugin from mysql.user;
+-----------+------------------+-----------------------+
| Host | User | Plugin |
+-----------+------------------+-----------------------+
| % | root | mysql_native_password |
| localhost | mysql.infoschema | caching_sha2_password |
| localhost | mysql.session | caching_sha2_password |
| localhost | mysql.sys | caching_sha2_password |
+-----------+------------------+-----------------------+
4 rows in set (0.00 sec)
mysql>
再測試連接,成功!文章來源:http://www.zghlxwxcb.cn/news/detail-722006.html
七、命令記錄
過程中敲過的一些命令:文章來源地址http://www.zghlxwxcb.cn/news/detail-722006.html
#安裝MYSQL8的yum源
[root@szaliyun ~]# yum localinstall https://repo.mysql.com//mysql80-community-release-el7-11.noarch.rpm
[root@szaliyun ~]# yum repolist enabled
[root@szaliyun ~]# yum repolist enabled | grep "mysql.*-community.*"
[root@szaliyun ~]# find / -name ib_logfile0 #查找文件
[root@szaliyun data]# mkdir ib_logfilebackup
[root@szaliyun data]# cp ib_logfile0 ib_logfilebackup/
#卸載mysql5.6
[root@szaliyun ~]# yum remove bt-mysql56-5.6.50-1.el7.x86_64
#卸載mysql-community-server
[root@szaliyun ~]# yum remove mysql-community-server-8.0.35-1.el7.x86_64
[root@szaliyun ~]# yum install mysql-community-server
[root@szaliyun ~]# systemctl start mysqld
[root@szaliyun ~]# systemctl status mysqld
[root@szaliyun ~]# cat /var/log/mysqld.log
[root@szaliyun ~]# which mysql
#重裝mysql客戶端
[root@szaliyun mysql]# yum reinstall mysql-community-client-8.0.35-1.el7.x86_64
[root@szaliyun ~]# firewall-cmd --zone=public --add-port=3306/tcp --permanent
[root@szaliyun ~]# firewall-cmd --reload
[root@szaliyun /]# mysql -u root -p
#修改密碼
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'New%Password4';
#放開所有地址訪問數(shù)據(jù)庫
mysql> update user set host = '%' where user = 'root';
#修改密碼規(guī)則
mysql> alter user root@'%' identified with mysql_native_password by 'New#password2';
到了這里,關(guān)于在CentOS上用yum方式安裝MySQL8過程記錄的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!