1. 在线安装MySQL8
#在线安装mysql8,@mysql模块将安装MySQL及其所有依赖项
dnf install @mysql
#查看安装的msyql信息
rpm -qa | grep mysql
#启动mysql服务并设置为开机自启
systemctl enable --now mysqld
#查看mysql是否正常运行
systemctl status mysqld
mysql正常运行显示如下图
#登录mysql,第一次登录没有密码,所以需要修改root账户密码
mysql -u root -p
#修改root账户密码---localhost指本地才可连接,远程不可访问,后面的'root'为新密码
use mysql;
alter user 'root'@'localhost' identified by 'root';
#退出mysql
quit
#再次登录需要使用密码了
2. 设置MySQL开放外网访问权限
1.查看root用户host及加密方式
#登录mysql
mysql -uroot -proot
#查看用户权限情况
use mysql;
select host,user,plugin from user;
2.更新用户host
#更新root用户的host,%表示任意IP都可连接,即可远程连接,localhost表示只能本地连接
update user set host='%' where user='root';
#查看更新结果
select host,user from user;
3.修改root用户权限
#修改root权限,第一个*表示通配数据库,也可指定数据库,第二个*表示通配表,也可指定表
grant all on *.* to 'root'@'%';
#更新权限
flush privileges;
#退出mysql
quit
4.放行端口或关闭防火墙
#查看防火墙运行状态
systemctl status firewalld
#放行指定端口(这里当然是放行3306),permenent表示设置为持久
firewall-cmd --permanent --add-port=3306/tcp
#查看放行结果
firewall-cmd --query-port=3306/tcp
#放行成功后重启防火墙
systemctl restart firewalld
#关闭指定端口
firewall-cmd --permanent --remove-port=3306/tcp
#关闭防火墙
systemctl stop firewall
5.使用Navicat远程连接mysql