Home > Database > Mysql Tutorial > 怎样设置才能允许外网访问MySQL

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

WBOY
Release: 2016-06-07 16:28:29
Original
1216 people have browsed it

设置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的配置文件,有的是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>grand all privileges on  *.*  to root@'%'  identifies  by ' xxxx';
其中 第一个*表示数据库名;第二个*表示该数据库的表名;如果像上面那样 *.*的话表示所有到数据库下到所有表都允许访问;
‘%':表示允许访问到mysql的ip地址;当然你也可以配置为具体到ip名称;%表示所有ip均可以访问;
 后面到‘xxxx'为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;

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template