tags:

views:

182

answers:

1

I have 10 tables in my database, where tbl_city and tbl_state.

structure of tbl_state is below

state_id    |int(10)  |UNSIGNED ZEROFILL  auto_increment 
state_name  |varchar(40) 

and structure of tbl_city is below

city_id     |int(10)  |UNSIGNED ZEROFILL  auto_increment 
city_name   |varchar(40) |
state_code  |int(10)  | UNSIGNED ZEROFILL

where state_code is references to state_id of tbl_state, now my problem is

when i export all data and import again...then it gives foreign key constraint fails error.... bcoz

when we export mysql dump, sql dump is generated alphabetically ordered tables
and tbl_city comes before tbl_state in database.

please suggest me how do i manage this??

is there any way that all tables comes in the order of foreign key references?

+1  A: 

You want to disable foreign key checks at start of the dump, and then enable them after all the data is dumped:

SET FOREIGN_KEY_CHECKS=0

... dump ...

SET FOREIGN_KEY_CHECKS=1
reko_t
i can't do this bcoz i m xporting data from a machine and importing on another machine, and this will be done by a non technical person. and this process will b continue once in a day forever... suggest me some other idea
diEcho
the technical person who is responsible for generating the dump should fix their script then. or use mysqldump which does this for you
reko_t
can u tell me the link where i can find some script which export mysql into xml from one machine and import xml into mysql to another machine
diEcho
You can use mysqldump with the --xml flag: http://dev.mysql.com/doc/refman/5.1/en/mysqldump.html
Ike Walker
And here's an article on importing the XML data back into a MySQL database: http://dev.mysql.com/tech-resources/articles/xml-in-mysql5.1-6.0.html#xml-5.1-importing
Ike Walker
listen to reko_t and create a script for the "dumb" end user to execute.
f00