mysql導數(shù)據(jù)遇到錯誤提示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;
按正常情況來說是不會出現(xiàn)這種情況的,這個語句只是控制當前session的查詢是否寫入binlog。群里的人都覺得這個問題很奇怪。
解決方案1:
大家看到既然是權(quán)限問題,那么就提權(quán)吧,或者使用root吧。但是前同事說是跳板機轉(zhuǎn)過去的,沒有辦法用root,而提權(quán)和授權(quán)(grant)也需要root權(quán)限。方案1被否。
解決方案2:
既然不能用root,只能想其它辦法了,但是我疑惑的是,為什么會出現(xiàn)用戶無法控制自己的session變量的情況?于是搜索了一下,跳到mysql官網(wǎng),找到這樣一段描述:
sql_log_binThis 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,無法在子查詢或者事務(wù)中執(zhí)行set @@session.sql_log_bin。但是盡信書不如無書,我自己在mysql中執(zhí)行了一下:
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已經(jīng)修復(fù)了,那這個同事用的mysql版本是不是聲名狼藉的mysql5.6?讓他確認了一下,確實是5.6。到此問題的根源找到了,解決方法也就有了。直接刪除sql中所有的set @@session.sql_log_bin語句就可以了。