Foreign key constraints while dumping data
Asked Answered
A

1

-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?

Annecorinne answered 5/9, 2009 at 5:52 Comment(2)
I have managed to solve it by adding echo "truncate table test.bus_stops" before mysqldump statement. But is there any better way?Annecorinne
TRUNCATE TABLE? But I don't understand what you're trying to do...Tatary
L
3

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

Loyalty answered 5/9, 2009 at 6:11 Comment(1)
I just re-read your question, I don't understand what you're trying to do eitherLoyalty

© 2022 - 2024 — McMap. All rights reserved.