Foreign key constraints while dumping data

。_饼干妹妹 提交于 2019-12-04 06:59:43

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/1382583/foreign-key-constraints-while-dumping-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!