1.在连接服务器后,操作mysql系统数据库
命令为: mysql -u root -p
use mysql;
![](http://upload-images.jianshu.io/upload_images/10063944-8aff9419a019937e.png?imageMogr2/auto-orient/strip|imageView2/2/w/568/format/webp)
查询用户表命令:
select User,authentication_string,Host from user;
![](http://upload-images.jianshu.io/upload_images/10063944-8efd351891a5e9fd.png?imageMogr2/auto-orient/strip|imageView2/2/w/508/format/webp)
这里也可以看出host默认都是localhost访问权限
接下来就是最重要的部分了:
1. GRANT ALL PRIVILEGES ON *.* TO ‘root’@’%’ IDENTIFIED BY ‘123456’
这里的123456为你给新增权限用户设置的密码,%代表所有主机,也可以具体到你的主机ip地址
2.flush privileges;这一步一定要做,不然无法成功! 这句表示从mysql数据库的grant表中重新加载权限数据
因为MySQL把权限都放在了cache中,所以在做完更改后需要重新加载。
执行完这两步,再次查询用户表命令:
select User,authentication_string,Host from user;
![](http://upload-images.jianshu.io/upload_images/10063944-b82de24fe3660f5e.png?imageMogr2/auto-orient/strip|imageView2/2/w/527/format/webp)
发现多了一个用户,该用户所有的主机都可以访问,此时再次用sqlyog访问连接成功!
作者:云扬_fb42
链接:https://www.jianshu.com/p/6066b163deb9
来源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。