Mysql 创建用户与权限操作

创建用户,并给予查看指定库的权限

mysql> create user test@localhost identified by '123456abc'; # create user 'test'@'localhost' identified by '123456abc'; 都可以
Query OK, 0 rows affected (0.00 sec)

mysql> grant all privileges on yii2_basic.* to test@localhost; # grant all privileges on yii2admin.* to 'denson'@'localhost';
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> exit;
Bye

给用户分配权限

mysql> grant all privileges on *.* to 'username'@'localhost' identified by 'password'

给用户分配指定库的权限

mysql> GRANT ALL PRIVILEGES ON database.* TO 'username'@'localhost' IDENTIFIED BY 'password';

给用户分配指定操作的权限

mysql> GRANT SELECT, UPDATE ON database.* TO 'username'@'localhost' IDENTIFIED BY 'password';

刷新权限

mysql> flush privileges;

删除用户

mysql> drop user username@localhsot;

删除权限

mysql> REVOKE ALL PRIVILEGES ON *.* FROM 'username'@'localhost';
    原文作者:denson
    原文地址: https://segmentfault.com/a/1190000012124900
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞