#进入mysql
mysql -h 127.0.0.1 -u root -p
#设置远程连接权限
grant all privileges on *.* to 'root'@'%' identified by '123456' with grant option;
#刷新权限
flush privileges;
#8.0.18版本
# 新建一个用户
create user 'test'@'%' identified by '123456';
# 授权
GRANT ALL PRIVILEGES ON *.* TO 'test'@'%';
# 刷新权限
flush privileges;
# 设置远程访问
ALTER USER 'test'@'%' IDENTIFIED WITH mysql_native_password BY '123456';
# 刷新权限
flush privileges;
四、防火墙设置
#编辑防火墙配置文件
vi /etc/sysconfig/iptables
-A IN_public_allow -p tcp -m tcp --dport 3306 -m conntrack --ctstate NEW -j ACCEPT
#重启防火墙
systemctl restart iptables
##如果是云服务需到云端配置安全组规则