您的位置:首页 > 数据库 > MySQL

怎样设置才能允许外网访问MySQL

2015-08-07 11:21 716 查看
设置mysql服务允许外网访问,修改mysql的配置文件,有的是my.ini,有的是my.cnf【linux】.

1:设置mysql的配置文件

/etc/mysql/my.cnf

找到 bind-address =127.0.0.1 将其注释掉;//作用是使得不再只允许本地访问;

  重启mysql:
/etc/init.d/mysql restart


2:登录mysql数据库:mysql -u root -p

  
mysql> use mysql;


  查询host值:

mysql> select user,host from user;


如果没有”%”这个host值,就执行下面这两句:

mysql> update user set Host='%' where User='root';


mysql> flush privileges;


或者也可以执行:

mysql>grant all privileges on  *.*  to root@'%'  identified by ' mypwd';


其中 第一个表示数据库名;第二个表示该数据库的表名;如果像上面那样 .的话表示所有到数据库下到所有表都允许访问;

‘%’:表示允许访问到mysql的ip地址;当然你也可以配置为具体到ip名称;%表示所有ip均可以访问;

后面到‘mypwd’为root 用户的password;

举例:

任意主机以用户root和密码mypwd连接到mysql服务器

mysql> grant all privileges on *.* to root@'%' identified by 'mypwd' with grant option;


mysql> flush privileges;


IP为192.168.1.102的主机以用户myuser和密码mypwd连接到mysql服务器

mysql> grant all privileges on *.* to myuser@'192.168.1.102' identified by 'mypwd' with grant option;


mysql> flush privileges;


转自51脚本

lnmp开启mysql远程连接:

https://bbs.vpser.net/thread-13563-1-1.html

iptables防火墙:

https://www.vpser.net/security/linux-iptables.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  mysql