How to drop and re-populate mysql databases?

十年热恋 提交于 2019-12-11 02:06:01

问题


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.


回答1:


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.




回答2:


From the MySQL console:

mysql> DROP DATABASE [dbName]; 
mysql> CREATE DATABASE [dbName];
mysql> USE [dbName];
mysql> SOURCE [pathToSQLDump];



回答3:


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



来源:https://stackoverflow.com/questions/13161130/how-to-drop-and-re-populate-mysql-databases

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!