当前位置: 代码迷 >> MySQL >> mysql IP限制 iP受权
  详细解决方案

mysql IP限制 iP受权

热度:193   发布时间:2016-05-05 16:36:03.0
mysql IP限制 iP授权
远程连接Mysql时提示如下:
错误码:1045
Access denied for user [email protected]'(using password:YES)

这个提示通常是由于Mysql默认的IP限制原因。

登录Mysql后执行
mysql>use mysql;mysql>select user,host from user;+------+-----------------------+| user | host                  |+------+-----------------------+| root | 127.0.0.1             || root | ::1                   || root | localhost             || root | localhost.localdomain |+------+-----------------------+4 rows in set (0.00 sec)


这里把本机IP授权后即可登录了,具体操作如下:
mysql>grant all on *.* to root@'10.190.0.118' identified by 'mysqlpwd';Query OK, 0 rows affected (0.00 sec)mysql>flush privileges;Query OK, 0 rows affected (0.00 sec)mysql>select user,host from user;+------+-----------------------+| user | host                  |+------+-----------------------+| root | 127.0.0.1             || root | 10.190.0.118          || root | ::1                   || root | localhost             || root | localhost.localdomain |+------+-----------------------+5 rows in set (0.00 sec)


mysql grant语法如下:
grant 权限名(所有的权限用all) on 库名(*全部).表名(*全部) to [email protected](可以用%表示所有的IP,也可以指定一个IP或IP段) identified by “密码”;

可以指定权限,例如:
GRANT select,insert,update,delete ON dbname.* to 'test_user'@'10.190.0.118'  identified by 'mysqlpwd'


收回权限,可以使用revoke,语法基本差不多,例如:
revoke select,insert,update,delete ON dbname.* to 'test_user'@'10.190.0.118'  identified by 'mysqlpwd'


最后记得操作完成要刷新权限,才能生效:
mysql>flush privileges;Query OK, 0 rows affected (0.00 sec)mysql>quit;Bye
  相关解决方案