[root@localhost ~]# /sbin/iptables -I INPUT -p tcp --dport 3306 -j ACCEPT
[root@localhost ~]# /etc/rc.d/init.d/iptables savebash: /etc/rc.d/init.d/iptables: 没有那个文件或目录[root@localhost ~]# /etc/init.d/iptables restartbash: /etc/init.d/iptables: 没有那个文件或目录[root@localhost ~]# /etc/init.d/iptables statusbash: /etc/init.d/iptables: 没有那个文件或目录
CentOS7改了,以上命令有问题了,下面的可以。
# systemctl stop firewalld.service
# systemctl disable firewalld.servie或者
# firewall-cmd --permanent --zone=public --add-port=3306/tcp
[root@localhost ~]# firewall-cmd --permanent --zone=public --add-port=3306/tcpsuccess紧接着,CentOS7上,
只允许用户root从ip为192.168.x.x的主机连接到mysql服务器,并使用password作为密码
GRANT ALL PRIVILEGES ON *.* TO 'root'@'192.168.x.x' IDENTIFIED BY 'password' WITH GRANT OPTION;
FLUSH PRIVILEGES;
操作如下:
登录到mysql
MariaDB [(none)]> use mysql;
MariaDB [mysql]>
MariaDB [mysql]> GRANT ALL PRIVILEGES ON *.* TO 'root'@'192.168.1.104' IDENTIFIED BY '123456' WITH GRANT OPTION;Query OK, 0 rows affected (0.00 sec)MariaDB [mysql]> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)MariaDB [mysql]> quit
Bye
客户端,连接成功。