Mysql – Recreated database or clear all data on import to it in MySQL

MySQL

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.

Best Answer

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`;