设置访问权限
查看授予账号的权限
创建 user jj , host 仅限本地主机登录:
create user 'jj'@'localhost' identified by 'happy' ;
使用下面命令查看授予账号的权限:
show grants for 'jj'@'localhost' ;
mysql> show grants for 'jj'@'localhost' ;
+----------------------------------------+
| Grants for jj@localhost |
+----------------------------------------+
| GRANT USAGE ON *.* TO `jj`@`localhost` |
+----------------------------------------+
1 row in set (0.005 sec)
mysql>
上面结果表明:对任何数据库和表都没有访问权限。
设置访问权限
下面的命令授予 user 'jj'@'localhost' 整个服务器的权限:
grant all on *.* to 'jj'@'localhost' ;
*.* 表示任何数据库及任何表。
mysql> grant all on *.* to 'jj'@'localhost' ;
Query OK, 0 rows affected (0.998 sec)
mysql>
切记一定要刷新授权才可生效:
flush privileges;
下面的命令撤销 user 'jj'@'localhost' 整个服务器的权限:
revoke all on *.* from 'jj'@'localhost' ;