MySQL设置所有IP地址都可以访问数据库

1. 登录MySQL

mysql -u root -p

2. 查询user表中的user列和host列的数据

select user,host from user;

查询结果应该如下图所示:
MySQL User表中的查询结果(修改前)

3. 向user表新增user=root,host=%的数据

update user set host='%' where user='root'
  • 1

grant all privileges on \*.* to root@'%'  identified  by 'root'
  • 1

其中 第一个*表示数据库名;第二个*表示该数据库的表名;如果像上面那样 *.*的话表示所有到数据库下到所有表都允许访问;
‘%’:表示允许访问到mysql的ip地址;当然你也可以配置为具体到ip名称;%表示所有ip均可以访问;

修改后的查询结果应该如下图所示:
MySQL User表中的查询结果(修改后)

posted @ 2020-09-23 16:18  李慕白520  阅读(4965)  评论(0编辑  收藏  举报