mysql删除用户
mysql中怎么删除用户呢?不知道的小伙伴来看看小编今天的分享吧!
mysql删除用户有两种方法:
1、使用drop
drop user XXX;删除已存在的用户,默认删除的是'XXX'@'%'这个用户,如果还有其他的用户如'XXX'@'localhost'等,不会一起被删除。如果要删除'XXX'@'localhost',使用drop删除时需要加上host即drop user 'XXX'@'localhost'。
2、使用delete
delete from user where user='XXX' and host='localhost';其中XXX为用户名,localhost为主机名。
3、drop和delete的区别:
drop不仅会将user表中的数据删除,还会删除其他权限表的内容。而delete只删除user表中的内容,所以使用delete删除用户后需要执行FLUSH PRIVILEGES;刷新权限,否则下次使用create语句创建用户时会报错。
拓展资料:
MySQL添加用户、删除用户、授权及撤销权限
1、创建用户:
mysql> insert into mysql.user(Host,User,Password) values("localhost","test",password("1234"));
#这样就创建了一个名为:test 密码为:1234 的用户。
注意:此处的"localhost",是指该用户只能在本地登录,不能在另外一台机器上远程登录。如果想远程登录的话,将"localhost"改为"%",表示在任何一台电脑上都可以登录。也可以指定某台机器(例如192.168.1.10),或某个网段(例如192.168.1.%)可以远程登录。
2、为用户授权:
授权格式:grant 权限 on 数据库.* to 用户名@登录主机 identified by "密码";
首先为用户创建一个数据库(testDB):
mysql>create database testDB;
授权test用户拥有testDB数据库的所有权限(某个数据库的所有权限):
mysql>grant all privileges on testDB.* to test@localhost identified by '1234';
mysql>flush privileges;//刷新系统权限表,即时生效
如果想指定某库的部分权限给某用户本地操作,可以这样来写:
mysql>grant select,update on testDB.* to test@localhost identified by '1234';
mysql>flush privileges;
#常用的权限有select,insert,update,delete,alter,create,drop等。可以查看mysql可授予用户的执行权限了解更多内容。
授权test用户拥有所有数据库的某些权限的远程操作:
mysql>grant select,delete,update,create,drop on *.* to test@"%" identified by "1234";
#test用户对所有数据库都有select,delete,update,create,drop 权限。
查看用户所授予的权限:
mysql> show grants for test@localhost;
3、删除用户:
mysql>Delete FROM user Where User='test' and Host='localhost';
mysql>flush privileges;
删除账户及权限:
>drop user 用户名@'%';
>drop user 用户名@ localhost;
4、修改指定用户密码:
mysql>update mysql.user set password=password('新密码') where User="test" and Host="localhost";
mysql>flush privileges;
5、撤销已经赋予用户的权限:
revoke 跟 grant 的语法差不多,只需要把关键字 “to” 换成 “from” 即可:
mysql>grant all on *.* to dba@localhost;
mysql>revoke all on *.* from dba@localhost;
6、MySQL grant、revoke 用户权限注意事项:
grant, revoke 用户权限后,该用户只有重新连接 MySQL 数据库,权限才能生效。
如果想让授权的用户,也可以将这些权限 grant 给其他用户,需要选项 "grant option"
mysql>grant select on testdb.* to dba@localhost with grant option;
mysql>grant select on testdb.* to dba@localhost with grant option;
这个特性一般用不到。实际中,数据库权限最好由 DBA 来统一管理。
-
感悟人生的经典句子2022 感悟人生的经典句子
1、千里之行,始于足下。改变将来,从现在开始。改变现在,就是改变未来。2、你配不上自己的野心,也辜负了曾经历的苦难。3、目标不是都能达到的,但它可以作为瞄准点。4、如果你还认为...
格言查看全文>> -
公司活动讲话稿四分钟范文
公司活动讲话稿四分钟范文,下面就来给大家详细介绍:公司活动讲话稿有三部分内容,第一部分写一个概括性的开头,总领全文;第二部分可以写具体的工作任务以及完成情况;第三部分写存在的不...
教育查看全文>> -
2019款尼桑奇骏报价多少钱?
2019款尼桑奇骏这款车报价介绍:1、2019款尼桑奇骏这款车厂商指导价:18.88-27.13万元,2019款新奇骏从发动机排量上分为2.0升和2.5升两款发动机,变速箱除2...
问答查看全文>> -
前挡玻璃有裂纹需要修补吗?
前挡玻璃有裂纹需要修补,轿车前挡风玻璃已经采用单件式弯曲挡风玻璃,并逐渐抛弃了平面型的挡风玻璃。轿车挡风玻璃一般都做成整体一幅式的大曲面型,上下左右都有一定的弧度。以下是汽车挡...
问答查看全文>>
推荐
- 1关于春天的说说心情短语 等待春天到来的心情246
- 2科目三转弯压线怎么办?108
- 3镀膜剂怎么用?241
- 4路虎发现神行油耗高吗?481
- 5有关传统文化的歇后语314
- 6随车千斤顶怎么使用329
- 7中东版普拉多4000油耗怎么样?325
- 8九代雅阁二手价格多少?365