整合出自:
- CentOS8卸载安装mysql8.0
- Linux 安装 MySQL
一、卸载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、查看是否有安装 mariadb,该软件与 MySQL 数据库有冲突,需要手动卸载
# 如果是 CentOS7 可以检测出已经安装了 mariadb
rpm -qa | grep mariadb
2、移除 MySQL 相关的软件
如果系统中没有安装过与 MySQL 相关的软件,直接跳到下一步
rpm -e --nodeps mariadb-libs-5.5.68-1.el7.x86_64
3、关闭selinux
vi /etc/selinux/config
找到
SELINUX=enforcing
修改
SELINUX=disabled
4、安装 openssl-devel(已安装跳过)
yum install openssl-devel -y
三、安装MysQL
1、官网链接下载
2、选择对应版本
3、下载到自己安装的路径下
mkdir /home/softwore/mysql-8.0.35
cd /home/softwore/mysql-8.0.35
wegt https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.35-1.el8.x86_64.rpm-bundle.tar
4、解压
tar -xvf mysql-8.0.35-1.el8.x86_64.rpm-bundle.tar
5、使用 rpm 安装
必须按照顺序执行命令,否则会出现依赖错误的报错
rpm -ivh mysql-community-common-8.0.35-1.el8.x86_64.rpm
rpm -ivh mysql-community-client-plugins-8.0.35-1.el8.x86_64.rpm
rpm -ivh mysql-community-libs-8.0.35-1.el8.x86_64.rpm
rpm -ivh mysql-community-client-8.0.35-1.el8.x86_64.rpm
rpm -ivh mysql-community-icu-data-files-8.0.35-1.el8.x86_64.rpm
rpm -ivh mysql-community-devel-8.0.35-1.el8.x86_64.rpm
rpm -ivh mysql-community-server-8.0.35-1.el8.x86_64.rpm
6、查看已安装的 MySQL 的版本
mysql --version
7、配置my.cof
注意:MySQL 不区分表名、数据库名和数据库模式名的大小写,需要先加lower_case_table_names=1,mysql8.0只能初始化时候配置,后面修改比较麻烦
vi /etc/my.cnf
8、启动mysql
#开机自启
systemctl enable mysqld
#启动
systemctl start mysqld
#查看状态
systemctl status mysqld
#重启
systemctl restart mysqld
#关闭
systemctl stop mysqld
#关闭开机自启
systemctl disable mysqld
启动成功
四、修改密码
1、获取 root 用户的初始密码
cat /var/log/mysqld.log | grep root@localhost
2、使用 root 用户登录到 MySQL 服务
mysql -u root -p
3、修改 root 的初始化密码
alter user root@localhost identified by 'Abu123456.';
4、开放远程访问权限(根据自己需求)进入mysql
#切换mysql数据库
use mysql;
#查看用户的访问权限 localhost:只可以本地访问 %:允许任意地方访问
select host, user, plugin from user;
#设置 root 用户任意地方可以访问
update user set host='%' where user='root';
#刷新权限
flush privileges;
#再次查看
select host, user, plugin from user;
5、修改密码策略
#修改密码策略
alter user 'root'@'%' identified with mysql_native_password by 'Abu123456.';
#刷新权限
flush privileges;