CentOS8卸载安装mysql8.0

操作环境:
CentOS 8.2
mysql8.0.27
大部分借鉴于:https://blog.csdn.net/qq_39150374/article/details/112471108

卸载mysql

1、查看mysql安装了哪些东西

[root@iZuf65saybbvavxkh38cdiZ mysql]# rpm -qa |grep -i mysql
mysql80-community-release-el8-1.noarch
mysql-community-server-8.0.27-1.el8.x86_64
mysql-community-client-plugins-8.0.27-1.el8.x86_64
mysql-community-libs-8.0.27-1.el8.x86_64
mysql-community-client-8.0.27-1.el8.x86_64
bt-mysql57-5.7.34-1.el8.x86_64
mysql-community-common-8.0.27-1.el8.x86_64
[root@iZuf65saybbvavxkh38cdiZ mysql]# 

2、通过yum remove 将以上内容删除

yum remove mysql80-community-release-el8-1.noarch
yum remove mysql-community-server-8.0.27-1.el8.x86_64
yum remove mysql-community-client-plugins-8.0.27-1.el8.x86_64
yum remove mysql-community-libs-8.0.27-1.el8.x86_64
yum remove mysql-community-client-8.0.27-1.el8.x86_64
yum remove bt-mysql57-5.7.34-1.el8.x86_64
yum remove mysql-community-common-8.0.27-1.el8.x86_64

3、检查是否卸载干净

rpm -qa |grep -i mysql

4、查找mysql相关目录

[root@iZuf65saybbvavxkh38cdiZ mysql]# find / -name mysql
find: ‘/proc/29250/task/29250/net’: Invalid argument
find: ‘/proc/29250/net’: Invalid argument
/etc/logrotate.d/mysql
/var/lib/selinux/targeted/active/modules/100/mysql
/var/lib/selinux/targeted/tmp/modules/100/mysql
/var/lib/mysql
/var/lib/mysql/mysql
/usr/bin/mysql
/usr/lib64/mysql
/usr/share/selinux/targeted/default/active/modules/100/mysql

同时对这些目录进行删除

rm -rf /etc/logrotate.d/mysql
rm -rf /var/lib/selinux/targeted/active/modules/100/mysql
rm -rf /var/lib/selinux/targeted/tmp/modules/100/mysql
rm -rf /var/lib/mysql
rm -rf /var/lib/mysql/mysql
rm -rf /usr/bin/mysql
rm -rf /usr/lib64/mysql
rm -rf /usr/share/selinux/targeted/default/active/modules/100/mysql

5、删除/etc/my.cnf 文件rm -rf /etc/my.cnf

6:删除 /var/log/mysql/mysqld.log文件。rm -rf /var/log/mysql/mysqld.log

完成以上内容则卸载完成mysql

安装mysql

安装前准备:

1、下载mysql安装包:

wget https://dev.mysql.com/get/mysql80-community-release-el8-1.noarch.rpm

yum install mysql80-community-release-el8-1.noarch.rpm

效果图:

CentOS8卸载安装mysql8.0_第1张图片
查看是否安装成功
在这里插入图片描述

2、检查数据源:

查看mysql源是否安装成功:yum repolist enabled | grep "mysql.*-community.*"

效果图:

image-20211112230359009

3、禁用CentOS8自带mysql模块

yum module disable mysql // 禁用命令

效果图:

CentOS8卸载安装mysql8.0_第2张图片

安装mysql

yum install mysql-community-server

CentOS8卸载安装mysql8.0_第3张图片

1、启动mysql

[root@iZuf6hx48jsavuzwp5hv7jZ soft]# /bin/systemctl start mysqld.service//启动命令
[root@iZuf6hx48jsavuzwp5hv7jZ soft]# service mysqld status //

效果图:

CentOS8卸载安装mysql8.0_第4张图片

2、显示随机密码:

grep 'temporary password' /var/log/mysqld.log

密码是host:后面的一串字符。

image-20211112230730906

3、登录mysql修改密码

mysql -u root -p //输入上面生成的密码

CentOS8卸载安装mysql8.0_第5张图片

修改过程:

ALTER USER 'root'@'localhost' IDENTIFIED BY 'Root_21root'; //因为我们随便修改密码时,一般都不满足它的策略
会报以下错误:
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements

解决办法:
一定要先修改默认密码为: Root_21root 满足它的策略,再进行下面的操作:
SHOW VARIABLES LIKE 'validate_password%'; //查看密码策略

修改密码长度:
set global validate_password.length=1; //(长度)
修改密码等级:
set global validate_password.policy=0; //(等级)

设置成自己想要的密码:
ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';

4、mysql开启远程访问

create user 'root'@'%' identified by 'root123'; //1、先创建权限记录
grant all privileges on *.* to 'root'@'%' with grant option; //2、授权

效果图:

CentOS8卸载安装mysql8.0_第6张图片

你可能感兴趣的:(Linux,mysql,数据库,linux)