문제

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?

도움이 되었습니까?

해결책

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.

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top