以下操作在Centos7.5上实操成功。
rpm -qa | grep -i mariadb(检查有没有mariadb)
rpm -e --nodeps mariadb-libs-5.5.56-2.el7.x86_64(不检查依赖直接卸载)
rpm -qa | grep mysql
wget https://repo.mysql.com//mysql80-community-release-el7-3.noarch.rpm
yum -y install mysql80-community-release-el7-3.noarch.rpm
rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
yum -y install mysql-community-server
systemctl start mysqld
systemctl status mysqld(如没运行,执行systemctl start mysqld)
cat /var/log/mysqld.log | grep password
到这里,mysql8.0已经安装完成,为了更方便地使用mysql,下面是修改密码和开启远程访问的操作。
vim /etc/my.cnf(编辑文件)
添加skip-grant-tables
wq!保存退出
systemctl restart mysqld(重启服务让配置生效)
mysql -uroot -p
use mysql;(切换到mysql库)
SHOW variables LIKE 'validate_password%';(非必要操作,查询表)
set global validate_password.policy=0;(把密码限制调低)
set global validate_password.length=4;(把密码限制字数调低)
flush privileges;(刷新生效)
ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';(设置密码123456)
flush privileges;(刷新生效)
select user,host,plugin from user;(查询表)
update user set host = '%' where user = 'root';(设置root任意地址访问)
update user set plugin = 'mysql_native_password' where user = 'root';(非必要操作,因mysql8.0已改为新插件caching_sha2_password,用navicat12登录会报错,可执行这条命令改回旧插件mysql_native_password即可,或者升级navicat到16版本,16版本已支持caching_sha2_password)
flush privileges;(刷新生效)
exit(退出mysql)
vim /etc/my.cnf(编辑文件)
把skip-grant-tables删除
wq!保存退出
systemctl restart mysqld(重启服务让配置生效)
systemctl status firewalld(检查防火墙是否开启,如没运行,执行systemctl start firewalld)
firewall-cmd --permanent --add-port=3306/tcp(永久添加3306端口)
firewall-cmd --reload(刷新生效)
firewall-cmd --list-ports(非必要操作,检查是否开启端口)
本地登录mysql成功
navicat16远程登录mysql成功