2

I need to test a MySQL database in another server. But database is too big to export and import. Besides I only need some part of database to test.

Let's assume that database has 20 tables and I need to get last 10000 records from each table. How can I create a mysqldump for this situation ?

(Related: How to use mysqldump for a portion of a table?)

Community
  • 1
  • 1
trante
  • 33,518
  • 47
  • 192
  • 272

2 Answers2

5

I found this solution. This dump can be done if all tables has id field. By ordering results by id, you can get results.

mysqldump --user=backup_user -p databasename 
   --where="1=1 ORDER BY id DESC LIMIT 10000" | gzip > /targetfolder/file.sql.gz
trante
  • 33,518
  • 47
  • 192
  • 272
3

You can use mysqldump with --where condition.

For example:-

mysqldump -u [username] -p [dbname] {--opt} --where="true limit 10000" > dump.sql
Aman Aggarwal
  • 17,619
  • 9
  • 53
  • 81
  • Well this dumps first 10000 records. Is it possible to get last 10000 records, if number of records is bigger then 10000. – trante Jul 15 '15 at 11:59