简体   繁体   中英

Is it possible to backup records from a particular MySQL table a few at time with mysqldump? It's a table with a lot of records

So I have a table with nearly 200,000 records that I want to clean up. However I want to back it up. I've tried using the phpMyAdmin interface but the script keeps timing out given the huge size of the database. I've event tried backing up 5000 at a time and it doesn't work.

I'm wondering if I'll have a better time doing this from the command line using the mysqldump command. However, I'm having a hard time coming up with the command to:

  • back up a particular database (say db1 )
  • back up a particular table in db1 (say table1 )
  • back up a few records at a time (say 2500)

I know that the issue is not a connectivity issue because I can connect to it.

Here's what I have so far:

mysqldump --opt -h somedomain.com -u dbuser -p dbpass db1 table1 > ./my-backup-file.sql

Any help would be greatly appreciated.

UPDATE :

I know what the problem is. A sign-up form was left open for anyone to sign up and a spam bot found it and hammered it with sign-up requests thereby creating something like ~ 199,980 new records in the database. So I know they're standard varchar and text data being inserted. What i want to know is the easiest, pain, free way to clean it up.

You could also use the --where argument like this:

--where="1=1 LIMIT 0, 2500"

This will append the LIMIT clause at the end of the query

I figured how to do it and correct me if there's a better way but here's how I did it:

I added a the --where= option and specified a condition where a column, say, user_id must be between 1 and 100 for example.

mysqldump --opt -h somedomain.com -u dbuser -p dbpass db1 table1 --where="user_id >= 1 AND user_id <= 100"  > ./my-backup-file.sql

and that did exactly what I wanted to it to do.

In hindsight I think I could've used this condition instead: --where="user_id BETWEEN 1 AND 100" , which, reads better.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM