davidahines
davidahines

Reputation: 4094

Is there an easy way to clone a database, it's structure, and the last 100 records?

I need a reasonably quick way to setup a test database that mirrors production.

Upvotes: 2

Views: 101

Answers (5)

Gilbert Le Blanc
Gilbert Le Blanc

Reputation: 51445

Cloning a schema and the associated tables and indexes are easy. Others have suggested mysqldump.

Selecting the most recent 100 rows of each of the tables is easy if and only if there are no foreign keys. If there are foreign keys, you'll have to develop a process to select the rows you want, and the associated rows, to maintain the referential integrity of the schema.

Upvotes: 0

aviad
aviad

Reputation: 8278

different vendors provide import\export APIs and tools that implement them (command-line and GUI). Usually export query looks something like

CREATE EXTERNAL TABLE :exportFileAbsolutePath
USING ( DELIMITER '','' Y2BASE 2000 REMOTESOURCE ''JDBC'' ESCAPECHAR ''\'' )
AS SELECT {1} FROM SCHEMA.{0}

Which DB vendor you work with?

Sorry did not see mysql tag. see http://snippets.dzone.com/posts/show/360

Upvotes: 0

Harry Joy
Harry Joy

Reputation: 59660

  1. Take backup of production database.
  2. When ever needed restore that backup in test database.

Upvotes: 0

Matt Ball
Matt Ball

Reputation: 359776

Just make a backup.

Upvotes: 1

Ken
Ken

Reputation: 613

Check out mysqldump --no-data

Upvotes: 3

Related Questions