mysql设置远程连接

mysql默认是不允许远程连接的,通过命令开启mysql远程连接

grant all on *.* to 用户名@"%" identified by "密码";
flush privileges;

说明:

grant 权限1,权限2,…权限n on 数据库名称.表名称 to 用户名@用户地址 identified by '连接密码';

权限1,权限2,…权限n代表select,insert,update,delete,create,drop,index,alter,grant,references,reload,shutdown,process,file等14个权限。

权限1,权限2,…权限n使用all代替时,表示赋予所有权限。

当数据库名和表名使用*.*替代时,表示能够访问所有数据库和所有表。

用户地址可以是localhost,也可以是ip地址、域名、机器名字,当使用%时表示可以从任何地址连接。

flush privileges; 刷新权限。

注意: 连接密码不能为空,否则创建失败。

示例

给ip为123.123.1.1设置远程连接,操作权限为所有,操作内容为test数据库下的所有表,连接用户名和密码分别为:test,testpass

grant all on test.* to test@"123.123.1.1" identified by 'testpass';

查看已设置的权限信息

show grant for 'test'@'123.123.1.1';

如果想查看所有的权限信息,直接使用show grants;即可。

远程相关操作

删除用户

drop user 'test'@'123.123.1.1';

删除指定ip

delete from user where host='123.123.1.1';
flush privileges;

重命名账户

rename user `test`@'123.123.1.1' to 'newtest'@'123.123.1.1';

修改密码

set password for 'test'@'123.123.1.1' = password('newpassword');
如果您觉得本文对您有用,欢迎捐赠或留言~
微信支付
支付宝

1条评论

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注