mysqldump―output details

by philipp   Last Updated August 14, 2019 00:06 AM - source

I am about to write a little program to process database dump files created by mysqldump and I would like to make sure that my expectations about the »anatomy« of mysqldump's output are right. So please check the statements below and correct the if they are wrong.

  1. When dumping text mysqldump uses a single quote (') to wrap the text to insert.*
  2. Inside these quotes mysqldump escapes single quotes, double quotes and Backslashes (',",\) with a Backslash.*
  3. »newline« characters are dumped as: \n, \r\n
  4. the value of each INSERT of a String is only in one line of the dump-file.

*if not specified differently in command-line arguments

In General my problem is that I could not find any documentation or resource about the »anatomy« of the generated output, I know that these are SQL statements, but especially the way String are handled is the part I am interested in, so if there exists any good Stuff read out there dealing with that, please let me know.

Thanks in ahead!

Answers 1

mysqldump is capable of dumping in three ways

  • SQL
  • CSV
  • XML


The standard format has directives in addition to regular table creation and INSERTs

The paradigm is always the same

  • ...

Even with the characters you are coding and delimiting around, please consider mysqldump also processes TEXT, BLOB, BINARY, and VARBINARY fields. Unless you remember to use the --hex-blob option, you could find your delimiter processing somewhat flimsy in the presence of those datatypes.

Another aspect to deal with is if you make each row a separate INSERT using --skip-extended-insert, thus increasing the amount of delimiters to parse and count.


You could export data in CSV format. You could even set the options for delimiting.

This would eliminate the need to guessing the delimiters by presetting them.


If you export the data as XML (using --xml), the anatomy of the dump may still be subject to the issues around TEXT, BLOB, BINARY, and VARBINARY fields.


If you need to examine how data is batched by mysqldump, see my post How we take dump with batch of records option?

MySQL (eh, Oracle) has basically left it to the discretion of the Community Users to parse mysqldumps. Using --hex-blob has probably saved many developer headaches in order to simplify text processing of mysqldumps. This would relieve MySQL of having to document mysqldump output characteristics.

As for your utility you are coding, you are either going to see strings delimited or hex encoded. No need to sweat details past these two possibilities.

I just thought of something else: doing mysqldump from Linux vs. Windows. Keep in mind that whichever OS platform you use to run mysqldump. code for that platform only. Otherwise, you may need two little programs, one for Linux and one for Windows. (I won't mention MacOS at this point)

August 16, 2013 07:03 AM

Related Questions

How do you mysqldump specific table(s)?

Updated June 19, 2015 23:02 PM

Backup and restore "mysql" database

Updated September 14, 2017 22:06 PM