MYSQL开启远程连接和关闭远程连接

https://blog.csdn.net/netuser1937/article/details/53782921?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-1.nonecase&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-1.nonecase

use mysql #打开mysql数据库

#将host设置为%表示任何ip都能连接mysql,当然您也可以将host指定为某个ip

update user set host='%' where user='root' and host='localhost';

flush privileges; #刷新权限表,使配置生效
     然后我们就能远程连接我们的mysql了。

3、如果您想关闭远程连接,恢复mysql的默认设置(只能本地连接),您可以通过以下步骤操作:

use mysql #打开mysql数据库

#将host设置为localhost表示只能本地连接mysql

update user set host='localhost' where user='root';

flush privileges; #刷新权限表,使配置生效
备注:您也可以添加一个用户名为yuancheng,密码为123456,权限为%(表示任意ip都能连接)的远程连接用户。

命令参考如下:


grant all on *.* to 'yuancheng'@'%' identified by '123456';
flush privileges;

————————————————
版权声明:本文为CSDN博主「相思比梦长」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/netuser1937/article/details/53782921

原文地址:https://www.cnblogs.com/sheseido/p/13080591.html