mysql> create user admin_x@localhost identified by 'abc123';
Query OK, 0 rows affected (0.01 sec)
检查用户是否在mysql.user:
mysql> select user, host from mysql.user where user='admin_x';
+---------+-----------+
| user | host |
+---------+-----------+
| admin_x | localhost |
+---------+-----------+
1 row in set (0.01 sec)
好的。
现在我们授予此用户对 db 的访问权限test:
mysql> grant all on test.* to admin_x@localhost;
Query OK, 0 rows affected (0.00 sec)
并检查它:
mysql> show grants for admin_x@localhost;
+-----------------------------------------------------------+
| Grants for admin_x@localhost |
+-----------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'admin_x'@'localhost' |
| GRANT ALL PRIVILEGES ON `test`.* TO 'admin_x'@'localhost' |
+-----------------------------------------------------------+
2 rows in set (0.00 sec)
现在从以下位置不正确地删除用户mysql.user:
mysql> delete from mysql.user where user='admin_x';
Query OK, 1 row affected (0.00 sec)
并且用户不再在mysql.user:
mysql> select user from mysql.user where user='admin_x';
Empty set (0.00 sec)
但是当你现在尝试新建它时,你会得到一个错误:
mysql> create user admin_x@localhost identified by 'abc123';
ERROR 1396 (HY000): Operation CREATE USER failed for 'admin_x'@'localhost'
那是因为admin_x@localhost仍然有权限存储在mysql.db:
mysql> select User from mysql.db where user='admin_x';
+---------+
| User |
+---------+
| admin_x |
+---------+
1 row in set (0.00 sec)
现在,当您删除用户时
mysql> drop user admin_x@localhost;
Query OK, 0 rows affected (0.00 sec)
它真的消失了,您可以再次创建它:
mysql> create user admin_x@localhost identified by 'abc123';
Query OK, 0 rows affected (0.00 sec)
当一个用户被创建并被授予权限,然后从 mysql.user 中删除而不是被删除时,就会发生这种情况:
首先,创建一个用户
admin_x@localhost
:检查用户是否在
mysql.user
:好的。
现在我们授予此用户对 db 的访问权限
test
:并检查它:
现在从以下位置不正确地删除用户
mysql.user
:并且用户不再在
mysql.user
:但是当你现在尝试新建它时,你会得到一个错误:
那是因为
admin_x@localhost
仍然有权限存储在mysql.db
:现在,当您删除用户时
它真的消失了,您可以再次创建它: