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社区版官网:
1. 找到“DEB Bundle”
2.右击“download”
3.复制链接
终端
- 下载安装包
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
-
找到下载安装包的路径解压压缩包
tar +压缩包tar
# 5.7.32版本为:
tar -xvf mysql-server_5.7.32-1ubuntu18.04_amd64.deb-bundle.tar
- 更新依赖源及安装libaio1、libtinfo5依赖
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install libaio1
sudo apt-get install libtinfo5
- 按下列顺序安装
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
- 继续安装依赖
sudo apt-get -f install
sudo apt-get -f install libmecab2
- 安装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
- 检测安装
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