MySQL 创建用户及权限的操作命令

MySQL创建新用户
CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'password';

赋予操作权限:
GRANT ALL PRIVILEGES ON database_name.table_name TO ‘username’@'localhost’;
GRANT ALL PRIVILEGES ON database_name.* TO ‘username’@'localhost’;

删除用户:
DROP USER ‘username’@‘localhost’;

刷新权限:
FLUSH PRIVILEGES;

显示所有用户:
mysql> SELECT user, host FROM mysql.user;
+------------------+-----------+
| user            | host      |
+------------------+-----------+
| debian-sys-maint | localhost |
| mysql.session    | localhost |
| mysql.sys        | localhost |
| phpmyadmin      | localhost |
| root            | localhost |
+------------------+-----------+

显示一个用户的权限:
mysql> SHOW GRANTS FOR 'root'@'localhost';
+---------------------------------------------------------------------+
| Grants for root@localhost                                          |
+---------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION |
| GRANT PROXY ON ''@'' TO 'root'@'localhost' WITH GRANT OPTION        |
+---------------------------------------------------------------------+

相关推荐