mysql 中 使用truncate table XXXX 的时候出现 DROP command denied to user 'xxx' for table ' YYY的问题解决

在MySQL中尝试使用Truncate Table操作时遇到DROP权限问题。由于从5.1.32版本开始,Truncate被视为DDL操作,对于非InnoDB引擎,它等同于Drop然后Create。在内存引擎的临时表上执行Truncate会提示缺少Drop权限。解决方案是使用root权限登录并执行GRANT DROP ON 表名 TO 用户名。

最近在使用全量更新数据的时候想使用truncate table的时候,在测试环境没有任何问题,但是在生产线上环境出现了如下的错误:

 

drop command denied to XXXX....的错误,一开始很是奇怪,明明自己使用的truncate 但是为什么会出现drop的错误呢?

经过查找资料:

【参考】http://dev.mysql.com/doc/refman/5.1/en/truncate-table.html

Beginning with MySQL 5.1.32, TRUNCATE TABLE is treated for purposes of binary logging and replication as DROP TABLE followed by CREATE TABLE — that is, as DDL rather than DML. This is due to the fact that, when using InnoDB and other transactional storage engines where the transaction isolation level does not allow for statement-based logging (READ COMMITTED or READ UNCOMMITTED), the statement was not logged and replicated when using STATEMENT or MIXED logging mode. (Bug#36763) However, it is still applied on replication slaves using InnoDB in the manner described previously. 

确认结论:Mysql 对于非INNODB的引擎,truncate的操作都是等价于先 drop table 再create table 来实现的,所以使用在临时表上(engine = memory)使用 truncate 操作的时候会提示没有 drop table 的权限

 

所以根据错误我们给这个没有权限的表格赋予权限即可:

使用root权限登录后执行下面的语句:

GRANT  DROP ON 表名 TO 用户名;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值