How to recreate db during import of the dump? By recreate, db drop or deletion of its data is meant.

mysql db -u root -p < dump.sql

It's possible of course to drop and create db manually or automate it using bash, but as import is run frequently, i would like it to be done automatically via mysql command if it's possible.

2 Answers 2


You need to add this mysql command in order to drop and create database in a dump script:

DROP DATABASE IF EXISTS `database_name`;
CREATE DATABASE `database_name`;
mysqldump ... --add-drop-database ...

Check out the vast number of other options, too.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.