Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to drop and re-populate mysql databases?

Tags:

mysql

I have a mysql database with 10 tables and need to drop and repopulate the database to run some performance tests. Using mysqldump, I can dump out the data. What steps should I follow next, to clear the database, and re-import? Will need to run this for different sizes of the database (i.e. tables with different number of rows) to calculate the db performance, so I need to make sure these steps can be replicated.

like image 523
absessive Avatar asked Dec 03 '25 11:12

absessive


2 Answers

You might want to look at the options on mysqldump such as --add-drop-database and --add-drop-table. I'd probably go for --add-drop-database in this case.

like image 80
Brian D Avatar answered Dec 06 '25 06:12

Brian D


1) take the dump

    drop database db_name
    create database db_name
    mysql -u user -p db_name < dump.sql

I am sure this can be repeated any number of times. Its idempotent

like image 22
Ravi Sankar Raju Avatar answered Dec 06 '25 07:12

Ravi Sankar Raju