mysql 用户权限控制、远程访问控制

mysql 用户权限控制、远程访问控制

打开root的远程访问权限

mysql> grant all privileges on *.* to root@'%' identified by "password" with grant option;
Query OK, 0 rows affected (0.01 sec)

grant命令详解


  • all privileges
    表示打开所有权限,也可以进行单独授权,如insert、update、delete、select权限等,多个权限用逗号隔开,如
mysql> grant insert,update,select on ......
  • on *.*
    on后面 .的前面表示哪个数据库,填*表示所有,.的后面表示哪个表,填*表示所有, *.*表示所有的数据库下的所有表。

  • to root@’localhost’
    to后面跟用户名,@后面表示IP,填localhost表示只允许本地访问,填%表示所有的IP都可以访问,也可以指定IP 如root@’192.168.3.3’。

  • identified by
    identified by 后面跟该用户的密码。

  • with grant option
    with grant option表示该用户是否权限授权给别的账户,比如拥有insert权限的用户是否能够创建拥有insert权限的账户。

例子

只允许用户inser、update、select,不允许delete

mysql> grant insert,update,select on *.* to user@'%' identified by "password" with grant option;

只允许192.168.3.3远程登录访问

mysql> grant all privileges on *.* to user@'192.168.3.3' identified by "password" with grant option;

只允许用户访问test数据库

mysql> grant all privileges on test.* to user@'%' identified by "password" with grant option;

猜你喜欢

转载自blog.csdn.net/wodecc_u/article/details/71440820