转储数据时的外键约束 [英] Foreign key constraints while dumping data
本文介绍了转储数据时的外键约束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
mysqldump --compact --no-create-info -h192.168.150.180 -uroot -p live pnlbus_stops | sed s / pnlbus_stops / bus_stops / g | mysql测试
我得到一个错误:
ERROR 1062(23000)at line 1:键1重复输入'AN'
这是因为测试数据库中的bus_stops表具有外键约束。在从live数据库插入数据之前,如何在测试数据库中截断bus_stops表格?解决方案
put p>
set FOREIGN_KEY_CHECKS = 0;
位于您的转储文件的顶部
并放入
SET FOREIGN_KEY_CHECKS = 1;
位于转储文件的底部
mysqldump --compact --no-create-info -h192.168.150.180 -uroot -p live pnlbus_stops | sed s/pnlbus_stops/bus_stops/g | mysql test
I am getting an error: ERROR 1062 (23000) at line 1: Duplicate entry 'AN' for key 1
This is because bus_stops table in the test DB has foreign key constraints. How do I truncate the bus_stops table from test database in a SINGLE STATEMENT before inserting from "live" DB?
解决方案
put
set FOREIGN_KEY_CHECKS = 0;
at the top of your dump file
and put
SET FOREIGN_KEY_CHECKS = 1;
at the bottom of your dump file
这篇关于转储数据时的外键约束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文