Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Taking Table Data Dump With Column Name

Tags:

mysql

I want a dump of specific table's data from one DB. I am using the Command mysqldump -t -uroot -p TEST Person Address Department > /home/Dumps/Desktop/dumb.sql My Problem is the DB which is i am going to import this dump has the same tables but different number of columns. For Example the Person table in New DB contains one more column compare to Test Db's Person Table. Because of this i could not import my dump. It shows an error "Column count doesn't match value count at row 1" I found what is the problem. In dump.sql the insert queries are like

INSERT INTO `Person` VALUES 
    (1,'1',NULL,'2012-05-22 08:05:34',NULL,'shobana',NULL),
    (2,'2',NULL,'2012-07-16 09:56:33',NULL,'prabu',NULL);

But if it is like this:

INSERT INTO `Person` 
   (column1,column2,column3,column4,column5,column6,column7) 
   VALUES 
   (1,'1',NULL,'2012-05-22 08:05:34',NULL,'shobana',NULL),
   (2,'2',NULL,'2012-07-16 09:56:33',NULL,'prabu',NULL);

I won't get any problem.

Is there any command to take data dump with column names mapping.

Can anybody please help me? Thanks in Advance..

like image 509
Sangeetha Krishnan Avatar asked Oct 11 '12 07:10

Sangeetha Krishnan


1 Answers

use:

mysqldump --complete-insert ....

This will add the column names and you will be able to import it.

like image 119
Nin Avatar answered Sep 24 '22 22:09

Nin