Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mysqldump: create column names for inserts when backing up

How do I instruct mysqldump to backup with column names in insert statements?
In my case I didn’t a normal back up with insert sql’s resulting in

LOCK TABLES `users` WRITE; /*!40000 ALTER TABLE `users`  INSERT INTO `users` VALUES (1 

structure.

Now I went ahead and removed a column from the schema in users. After this when I run the backup sql’s I get a column number mismatch error.

To fix this how do I go about instructing mysqldump to write column names too? Here is how I do it now

mysqldump --host=${dbserver} --user=${dbusername} --password=${dbpassword} \           --no-create-db --no-create-info --extended-insert --single-transaction \           --compress tablename   

On a broader level, what’s the best practice to manage these schema changes?

like image 232
Quintin Par Avatar asked Mar 29 '11 03:03

Quintin Par


People also ask

What is -- opt in Mysqldump?

The --opt option (and hence --quick ) is enabled by default, so to enable memory buffering, use --skip-quick . If you are using a recent version of mysqldump to generate a dump to be reloaded into a very old MySQL server, use the --skip-opt option instead of the --opt or --extended-insert option.

How can you list all columns for a given table?

You can list a table's columns with the mysqlshow db_name tbl_name command.

Does Mysqldump lock the database?

By default, the mysqldump utility, which allows to back a MySQL database, will perform a lock on all tables until the backup is complete. In many cases, the amount of data in the database and the uptime requirements will not allow this lock in real life.


1 Answers

Use --complete-insert in the mysqldump command params

like image 198
Cherian Avatar answered Oct 11 '22 12:10

Cherian