MySQL8.0降級安裝5.7


本博客旨在自我學習使用,如有任何疑問請及時聯系博主

前言

基於OpenHarmony的FA數字管家服務端

默認情況下,Ubuntu20.04安裝MySQL的版本為8.0。但8.0更加嚴格的加密規則,使得一些配置難以實現,故該項目中先進行MySQL 8.0.26 → MySQL 5.7.32

為什么不選擇MySQL 5.7的最新版本 5.7.39呢?

我也不知道,反正我一開始降級為5.7.39的時候連mysql的server都跑不起來,所以選擇了5.7.32

卸載MySQL 8.0.26

1. 查看MySQL的依賴項

dpkg --list|grep mysql

2. 卸載 mysql-common

sudo apt remove mysql-common

3. 卸載 mysql-server

sudo apt autoremove --purge mysql-server

4. 清除殘留數據

dpkg -l|grep ^rc|awk '{print$2}'|sudo xargs dpkg -P

5. 再次查看MySQL的剩余依賴項(一般這時候就卸載干凈了)

dpkg --list|grep mysql

6. 繼續刪除依賴項(如果步驟 5還有剩余依賴,則繼續 6)

sudo apt autoremove --purge mysql-apt-config

安裝MySQL 5.7.32

MySQL社區版官網:

MySQL_community

1. 找到“DEB Bundle”

2.右擊“download”

3.復制鏈接

終端

  1. 下載安裝包wget +url
# 5.7.32版本為:
wget https://downloads.mysql.com/archives/get/p/23/file/mysql-server_5.7.32-1ubuntu18.04_amd64.deb-bundle.tar](https://downloads.mysql.com/archives/get/p/23/file/mysql-server_5.7.32-1ubuntu18.04_amd64.deb-bundle.tar 
  1. 找到下載安裝包的路徑解壓壓縮包

    tar +壓縮包tar

# 5.7.32版本為:
tar -xvf mysql-server_5.7.32-1ubuntu18.04_amd64.deb-bundle.tar

  1. 更新依賴源及安裝libaio1、libtinfo5依賴
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install libaio1
sudo apt-get install libtinfo5
  1. 按下列順序安裝
sudo dpkg -i mysql-common_5.7.32-1ubuntu18.04_amd64.deb
# 下一行代碼會進入一個古老的界面,並讓你輸入密碼,這個密碼就是mysql的root密碼
sudo dpkg-preconfigure mysql-community-server_5.7.32-1ubuntu18.04_amd64.deb 
sudo dpkg -i libmysqlclient20_5.7.32-1ubuntu18.04_amd64.deb
sudo dpkg -i libmysqlclient-dev_5.7.32-1ubuntu18.04_amd64.deb
sudo dpkg -i libmysqld-dev_5.7.32-1ubuntu18.04_amd64.deb
sudo dpkg -i mysql-community-client_5.7.32-1ubuntu18.04_amd64.deb
sudo dpkg -i mysql-client_5.7.32-1ubuntu18.04_amd64.deb
sudo dpkg -i mysql-common_5.7.32-1ubuntu18.04_amd64.deb
  1. 繼續安裝依賴
sudo apt-get -f install
sudo apt-get -f install libmecab2
  1. 安裝mysql-server
sudo dpkg -i mysql-community-server_5.7.32-1ubuntu18.04_amd64.deb
sudo dpkg -i mysql-server_5.7.32-1ubuntu18.04_amd64.deb
  1. 檢測安裝
mysql -u root -p
# 然后會讓輸入密碼,這個密碼就是剛剛設置的密碼

顯示如下界面表示安裝成功

![](https://tva1.sinaimg.cn/large/e6c9d24egy1h0e503ppxnj20vk0amjt0.jpg)

配置MySQL 5.7.32

1. 初始化配置

sudo mysql_secure_installation

2. 配置說明

# 1  選擇N,不會進行密碼的強校驗;Y 進行
VALIDATE PASSWORD PLUGIN can be used to test passwords...
Press y|Y for Yes, any other key for No:

# 2 數據庫的root密碼,該密碼會把上面設置過的root密碼覆蓋
Please set the password for root here...
New password: # (輸入密碼)
Re-enter new password: # (重復輸入)

# 3  選擇N,不刪除匿名用戶;Y 刪除
By default, a MySQL installation has an anonymous user allowing anyone to log into MySQL without having to have a user account created for them...
Remove anonymous users? (Press y|Y for Yes, any other key for No) :

# 4  選擇N,允許root遠程連接;Y 不允許
Normally, root should only be allowed to connect from,'localhost'. This ensures that someone cannot guess at the root password from the network...
Disallow root login remotely? (Press y|Y for Yes, any other key for No) :
# 5 選擇N,不刪除test數據庫;Y 刪除
By default, MySQL comes with a database named 'test' that anyone can access...
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : 

# 6  選擇Y,修改權限立即生效;N 待會生效
Reloading the privilege tables will ensure that all changes made so far will take effect immediately.
Reload privilege tables now? (Press y|Y for Yes, any other key for No) :

3. 檢查mysql服務狀態

systemctl status mysql.service

密碼登陸mysql

先登陸mysql mysql

use mysql; #mysql表

# 密碼改為自己的root用戶密碼
update user set authentication_string=PASSWORD("密碼") where user='root';

# 更新插件
update user set plugin="mysql_natice_password";

# 刷新權限后退出重新登錄即可
flush privileges;
quit;
mysql -u root -p

WelCome!

原帖:wolai


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM