mysql导数据遇到错误提示ERROR 1227,Acess denied

作者:天一阁图书管理员

今天群里有前同事在问mysqldump出来的sql文件在导入的时候,报错error1227(42000)at line 18: Acess denied; you need (at least one of) the SUPER privilege(s) for this operation

定位到18行显示的是一个这样的语句: set @@session.sql_log_bin=0;

按正常情况来说是不会出现这种情况的,这个语句只是控制当前session的查询是否写入binlog。群里的人都觉得这个问题很奇怪。

解决方案1:
大家看到既然是权限问题,那么就提权吧,或者使用root吧。但是前同事说是跳板机转过去的,没有办法用root,而提权和授权(grant)也需要root权限。方案1被否。

解决方案2:
既然不能用root,只能想其它办法了,但是我疑惑的是,为什么会出现用户无法控制自己的session变量的情况?于是搜索了一下,跳到mysql官网,找到这样一段描述:
sql_log_bin
This variable controls whether logging to the binary log is done. The default value is 1 (do logging). To change logging for the current session, change the session value of this variable. The session user must have the [SUPER ](https://dev.mysql.com/doc/refman/5.7/en/privileges-provided.html#priv_super) privilege to set this variable. *Setting this variable to 0 prevents GTIDs from being assigned to transactions in the binary log*. If you are using GTIDs for replication, this means that, even when binary logging is later enabled once again, the GTIDs written into the log from this point do not account for any transactions that occurred in the meantime—in effect, those transactions are lost. In MySQL 5.7, it is not possible to set @@session.sql_log_bin within a transaction or subquery. (Bug #53437)
注意最后一行,上面说MySQL5.7有个bug,无法在子查询或者事务中执行set @@session.sql_log_bin。但是尽信书不如无书,我自己在mysql中执行了一下:

mysql> select version();
+-------------------------+
| version()               |
+-------------------------+
| 5.7.16-0ubuntu0.16.04.1 |
+-------------------------+
1 row in set (0.00 sec)

mysql> set @@session.sql_log_bin=0;
Query OK, 0 rows affected (0.03 sec)

说明这个bug已经修复了,那这个同事用的mysql版本是不是声名狼藉的mysql5.6?让他确认了一下,确实是5.6。到此问题的根源找到了,解决方法也就有了。直接删除sql中所有的set @@session.sql_log_bin语句就可以了。

  • 4
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值