一、卸载旧版本
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
5、同时对这些目录进行删除
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
6、删除/etc/my.cnf 文件rm -rf /etc/my.cnf
7、删除 /var/log/mysql/mysqld.log文件。rm -rf /var/log/mysql/mysqld.log
完成以上内容则卸载完成mysq
二、卸载 mariadb
1、查看是否有安装 mariadb,该软件与 MySQL 数据库有冲突,需要手动卸载
# 如果是 CentOS7 可以检测出已经安装了 mariadb
rpm -qa | grep mariadb
2、删除 mariadb
rpm -e --nodeps mariadb-libs-5.5.68-1.el7.x86_64
三、安装
1、进入MySQL官网 >> downloads >> MySQL Community(GPL)Downloads
![图片[1]-centos 安装mysql8-深吸氧](https://xiyang-blog.oss-cn-hangzhou.aliyuncs.com/blog/2024/08/20240812113007859-1024x604.png)
![图片[2]-centos 安装mysql8-深吸氧](https://xiyang-blog.oss-cn-hangzhou.aliyuncs.com/blog/2024/08/20240812113052298-1024x681.png)
点击MySQL Community Server
![图片[3]-centos 安装mysql8-深吸氧](https://xiyang-blog.oss-cn-hangzhou.aliyuncs.com/blog/2024/08/20240812113155693-1024x748.png)
2、根据自己的服务器架构和Linux版本选择软件
//查看Linux架构
uname -m
![图片[4]-centos 安装mysql8-深吸氧](https://xiyang-blog.oss-cn-hangzhou.aliyuncs.com/blog/2024/08/20240812113627853-1024x808.png)
3、下载到自己安装的路径下
mkdir /home/softwore/mysql
cd /home/softwore/mysql
wegt https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.4.2-1.el7.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.4.2-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-plugins-8.4.2-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-8.4.2-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-8.4.2-1.el7.x86_64.rpm
rpm -ivh mysql-community-icu-data-files-8.4.2-1.el7.x86_64.rpm
rpm -ivh mysql-community-devel-8.4.2-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-8.4.2-1.el7.x86_64.rpm
问题1:
![图片[5]-centos 安装mysql8-深吸氧](https://xiyang-blog.oss-cn-hangzhou.aliyuncs.com/blog/2024/08/20240812114601658-1024x98.png)
解决方案:
yum install openssl-devel
问题2:
![图片[6]-centos 安装mysql8-深吸氧](https://xiyang-blog.oss-cn-hangzhou.aliyuncs.com/blog/2024/08/20240812114724527-1024x157.png)
解决方案:
yum install net-tools
yum install -y perl-Module-Install.noarch
6、查看已安装的 MySQL 的版本
mysql --version
7、配置my.cof
设置,表名不区分大小写,在[mysqld]下加入一行:lower_case_table_names=1
8、修改安装目录的所有者/所属组,使用户拥有访问MySQL文件夹的权限
chown -R mysql:mysql /var/lib/mysql
9、初始化
mysqld --initialize --console
10、启动mysql
#开机自启
systemctl enable mysqld
#启动
systemctl start mysqld
#查看状态
systemctl status mysqld
#重启
systemctl restart mysqld
#关闭
systemctl stop mysqld
#关闭开机自启
systemctl disable mysqld
11、获取 root 用户的初始密码
cat /var/log/mysqld.log | grep root@localhost
![图片[7]-centos 安装mysql8-深吸氧](https://xiyang-blog.oss-cn-hangzhou.aliyuncs.com/blog/2024/05/20240812121530704-1024x47.png)
© 版权声明
THE END
暂无评论内容