今天在用MySQL Utilities工具集里的mysqldbcopy同步表結(jié)構(gòu)時(shí)轮蜕,報(bào)錯(cuò)了:
ERROR: Query failed. 1238 (HY000): Variable 'foreign_key_checks' is a SESSION variable
原來(lái)是mysqldbcopy在同步表結(jié)構(gòu)到目的端時(shí)會(huì)先外鍵檢查烁竭,假如目的端開(kāi)啟了則mysqldbcopy先禁用外鍵檢查碑韵;在這里失敗了汹忠,因?yàn)榈桶姹镜腗ySQL(這里目的端是5.1)的foreign_key_checks還不是全局變量:
mysql> select version();
+--------------------+
| version() |
+--------------------+
| 5.1.58-rel12.9-log |
+--------------------+
1 row in set (0.00 sec)
mysql> set global foreign_key_checks=off;
ERROR 1228 (HY000): Variable 'foreign_key_checks' is a SESSION variable and can't be used with SET GLOBAL
解決很簡(jiǎn)單秉版,在mysqldbcopy的源代碼里禁用掉這個(gè)檢查就行了:
vim ....../site-packages/mysql/utilities/command/dbcopy.py
...
# 注釋掉下面這行
# destination.disable_foreign_key_checks(True)
...