MySQL如何查看,删除用户

MySQL如何查看,删除用户,第1张

1.查看所有用户(需要在root用户下进行)

select host,user,password from mysql.user

2.删除用户

mysql>Delete FROM user Where User='用户名' and Host='上图有个host列表所示'//删除用户

例:mysql>Delete FROM user Where User='yl' and Host='localhost'

mysql>flush privileges//刷新权限

mysql>drop database ylDB//删除用户的数据库

1.查看所有用户(需要在root用户下进行)

select

host,user,password

from

mysql.user

2.删除用户

mysql>delete

from

user

where

user='用户名'

and

host='上图有个host列表所示'//删除用户

例:mysql>delete

from

user

where

user='yl'

and

host='localhost'

mysql>flush

privileges

//刷新权限

mysql>drop

database

yldb

//删除用户的数据库

(一)drop user 用户名

语法:drop user 用户名

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

(二)delete from user where user="用户名" and host="localhost"

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

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


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/7497694.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-06
下一篇 2023-04-06

发表评论

登录后才能评论

评论列表(0条)

保存