今天在用MySQL Utilities工具集里的mysqldbcopy同步表结构时,报错了:
ERROR: Query failed. 1238 (HY000): Variable 'foreign_key_checks' is a SESSION variable
原来是mysqldbcopy在同步表结构到目的端时会先外键检查,假如目的端开启了则mysqldbcopy先禁用外键检查;在这里失败了,因为低版本的MySQL(这里目的端是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
解决很简单,在mysqldbcopy的源代码里禁用掉这个检查就行了:
vim ....../site-packages/mysql/utilities/command/dbcopy.py
...
# 注释掉下面这行
# destination.disable_foreign_key_checks(True)
...