views:

41

answers:

2

Hello stackoverflow! First time poster here. I'm having problems re-importing a database dump made by mysqldump. I ran mysqldump with the order-by-primary option, and I had it run on a table with a unique key (and no explicit primary key, so it sorted by that unique key). My objective in this case was to re-create the table, making the unique key into the primary key.

This dump took a very long time (around 10 days) and it would be a major pain in the ass to run it again. I tried reimporting the dump (with the appropriate schema changes), but mysql choked midway through. I looked in the dumpfile, at the place where it choked - and it looks like someone inserted a spam email right into the text of the dumpfile.

Fortunately, it looks like the damage was isolated, I'm able to see the key right before the garbage, and right after.

tl;dr: if I just spliced out the garbage, I dont know how many keys will be missing between the one before and the one after - the dump is sorted by that unique key, so it makes life easier in that respect. Does mysql have a way to retrieve all rows between two entries in an index?

The key is a 32-character hex string, stored in a CHAR(32) type column. I'm pretty sure I can't use the < or > operators on strings... so any suggestions?

+2  A: 

Sorting the mysqldump on the primary key (or unique key) is what made it take so long. Ten days is pretty unbelievable, though.

Doing a sort like this is useful only when you want to backup a MyISAM table and restore it to an InnoDB table. Is this what you're doing?

MySQL certainly does have a way to dump subsets of a table. Check out the --where option of mysqldump. This should allow you to back up the rows that got corrupted.

And yes, you can use < and > on strings in SQL. You can also use the BETWEEN predicate.

Bill Karwin
I'm actually dumping from innodb to insert into an innodb table. I had read elsewhere that a order-by-primary is the thing to do when inserting into innodb. It's a 43GB table, so I kind of expected the long delay, I just didn't expect to have to do it twice!
frank
+1  A: 

My first question would be, how could a Spam mail make it into your database dump and destroy it?

I am guessing it comes from out of one of your data columns, right? Can you show how this E-Mail and how it managed to disturb your dump's structure?

Maybe it was some sort of header injection that caused the dump to insert line breaks where is shouldn't have, I don't know. Anyway, clearing that up would be first priority in my opinion.

Pekka
It's the oddest thing. I did the BETWEEN query as recommended by Bill, and none of the rows appear to have the data that corrupted my dump.
frank
It's possible the dump file is corrupted, but not the database.
Bill Karwin