1、登录数据库
use mysql;
update user set host = '%' where user = 'root';
/*
*如果直接进行授权,会报
You are not allowed to create a user with GRANT错误
所以先对host进行修改
*/
2、授权
GRANT ALL ON *.* TO 'root'@'%'
//如果要指定ip,把%改了即可
flush privileges;//刷新
3、更改密码的加密方式,以方便Navicat等工具能够连接
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'password';
//password里面填你的密码
select host,user,plugin from user;
//查看一下加密方式是否生效
4、对外开放3306端口
firewall-cmd --zone=public --add-port=3306/tcp --permanent
5、重启防火墙
firewall-cmd --reload
firewall-cmd --list-ports //查看开放端口的列表
6、使用ifconfig查询服务器ip地址
//如果没有ifconfig命令,可以使用yum命令查询
yum search ifconfig
//安装ifconfig
yum -y install net-tools.x86_64