设置Mysql5.6允许外网访问
设置mysql用户支持外网访问步骤:
需要使用root权限登录mysql,更新mysql.user表,设置指定用户的Host字段为%,默认一般为127.0.0.1或者localhost。
1.登录数据库
1 mysql -u root -p
输入密码
1 mysql> use mysql;
2.查询host
1 mysql> select user,host from user;
3.创建host
如果没有"%"这个host值,就执行下面这两句:
1 mysql> update user set host='%' where user='root'; 2 mysql> flush privileges;
4.授权用户
(1)任意主机以用户root和密码mypwd连接到mysql服务器
1 mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'mypwd' WITH GRANT OPTION; 2 mysql> flush privileges;
(2)IP为192.168.133.128的主机以用户myuser和密码mypwd连接到mysql服务器
1 1 mysql> GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'192.168.133.128' IDENTIFIED BY 'mypwd' WITH GRANT OPTION; 2 2 mysql> flush privileges;