mysql8.0.15 删除用户drop和delete区别

以删除test用户为例,如下:

1.drop user test; 

语法:drop user 用户名; 

作用:删除已经存在的用户,例如要删除test这个用户,(drop user test;)默认删除的是test@'%'这个用户,如果还有其他用户,例如test@'localhost',test@'ip',则不会一起被删除。如果只存在一个用户test@'localhost',使用语句(drop user test)会报错,应该用(drop user test@'localhost';)如果不能确定(用户名@机器名)中的机器名,可以在mysql中的user表中进行查找,user列对应的是用户名,host列对应的是机器名。 

2.delete from user where user='用户名' and host='localhost'; 

delete也是删除用户的方法,例如要删除test@'localhost'用户,则可以(delete from user where user='test' and host='localhost';)

注:drop删除掉的用户不仅将user表中的数据删除,还会删除诸如db和其他权限表的内容。而delete只是删除了user表的内容,其他表不会被删除,后期如果命名一个和已删除用户相同的名字,权限就会被继承。

猜你喜欢

转载自blog.csdn.net/liliuqing/article/details/88760327