views:

564

answers:

3

I'm using mysqldump in a cron job to backup a database with over 2 million rows.

It creates a text file which can be used to restore the datalog from the command line.

I thought it would be useful to edit the dump before a restore as a quick way of changing values and table or column names - at least until I learn more and become confident about doing it with ALTER and UPDATE.

Editing large text files does not bother me, but I was surprised to find that in a 250 megabyte dump of my database, there were only about 300 lines. Each line was something like 800k characters long.

Is there another way of generating dumps with more control over line length?

Or should I post-process the dump with tools like sed or Perl?

A: 

Post-process the dump file with python. You may be happier than perl or sed.

If you're running on Linux, you already have it installed. If you're running on Windows, the installer is painless.

Before that, however, learn to use SQL UPDATE and SQL ALTER. You'll be happiest doing things the right way.

S.Lott
I prefer Perl or sed, simply because that's what I'm used to.And although there's a certain satisfaction in editing a big file, I will learn the SQL commands, I promise.
pavium
+7  A: 

By default, mysqldump generates only one INSERT command per table, resulting in one (very long) line of inserted data for each table that got dumped. This is essentially because the "batch" inserts are much faster than if it generated a separate INSERT query for every record in every table.

So, it's not that mysqldump has created arbitrarily long lines, and you can just impose some other cutoff length. The lines are long for a reason.

If it's really important to get the INSERTs broken down onto multiple lines, you can indicate that with:

mysqldump --extended-insert=FALSE --complete-insert=TRUE ...

Note, however, that restoring tables will take longer in this format.

VoteyDisciple
I had looked in the mysqldump man page, and tried --extended-insert=FALSE but --complete-insert=TRUE is new to me. I'll try it, thanks.
pavium
A: 

The mysqldump MySQL page might have something your looking for, there are a number of options which can be passed. At a quick glance I didn't see anything about row length but there are a couple of options that might work for you. Posting you mysqldump command would help out as well as some of the dump file.

Phill Pafford
Alas, my employer would certainly take exception to my publishing bits of the EXTREMELY sensistive data in the database. I'd better not risk it.The mysqldump command is in a bash scriptSUFFIX=`date +%y%m%d`mysqldump --opt -q --compact db1 | bzip2 -c DB1.$SUFFIX.bz2
pavium
There were backticks in there, of course. I should have used $() in the comment.
pavium