1、首先开放mysql远程访问权限
mysql> USE mysql;
Database changed
//赋予任何主机访问数据的权限
mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'WITH GRANT OPTION
//允许用户 eaphy 使用密码 123456 从任何主机连接到mysql服务器的话。
mysql>GRANT ALL PRIVILEGES ON *.* TO 'eaphy'@'%'IDENTIFIED BY '123456' WITH GRANT OPTION;
//允许用户 eaphy 从ip为192.168.0.8的主机连接到mysql服务器,并使用 123456 作为密码
mysql>GRANT ALL PRIVILEGES ON *.* TO 'eaphy'@'192.168.0.8'IDENTIFIED BY '123456' WITH GRANT OPTION;
//修改生效
mysql>FLUSH PRIVILEGES
mysql>EXIT
2、开放 3306 端口
// centos 7
[eaphy@localhost /]$ firewall-cmd --zone=public --add-port=3306/tcp --permanent
success
[eaphy@localhost /]$ firewall-cmd --reload
success