一、卸载MariaDB
1.检索系统中MariaDB版本
rpm -qa | grep mariadb
2.卸载MariaDB
rpm -e --nodeps mariadb-libs-5.5.65-1.el7.x86_64
二、安装Mysql
1.下载对应版本的mysql安装包
https://dev.mysql.com/downloads/mysql/
2.将mysql安装包上传至centos服务器
使用xshell连接服务器,使用rz命令上传文件或者Xftp等其他软件传输至服务器
如果没有rz,先安装
yum install -y lrzsz
3.解压安装包
mkdir mysql
tar -xvf mysql-8.0.23-1.el7.x86_64.rpm-bundle.tar
4.释放组件
rpm -ivh mysql-community-common-8.0.23-1.el7.x86_64.rpm --nodeps --force
rpm -ivh mysql-community-libs-8.0.23-1.el7.x86_64.rpm --nodeps --force
rpm -ivh mysql-community-client-8.0.23-1.el7.x86_64.rpm --nodeps --force
rpm -ivh mysql-community-server-8.0.23-1.el7.x86_64.rpm --nodeps --force
5.查看mysql安装包
rpm -qa | grep mysql
6.初始化mysql
mysqld --initialize
如果初始化报如下错误:
mysqld: error while loading shared libraries: libnuma.so.1: cannot open shared object file: No such file or directory
解决方案:
yum install -y numactl
7.配置mysql
更改属组
chown mysql:mysql /var/lib/mysql -R
启动mysql
systemctl start mysqld.service
开机启动
systemctl enable mysqld
查看数据库的密码
cat /var/log/mysqld.log | grep password
登录数据库
mysql -uroot -p
修改本地登录密码
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'xxxxxxxxxx';
远程访问授权
create user 'root'@'%' identified with mysql_native_password by 'xxxxxxxxxx';
grant all privileges on *.* to 'root'@'%' with grant option;
flush privileges;
防火墙放开mysql 3306端口
使用mysql客户端 navicat连接