3

i want to use mysqldump so that it includes the statement to create database if not exists, and drop database if exists. is this possible? what options can I use?

user12145
  • 1,115
  • 6
  • 28
  • 47

2 Answers2

3

You can get MYSQLDump to drop the database before creating it by adding

--add-drop-database

To your MYSQLDump command. You should already have the create database command in there.

Sam Cogan
  • 38,736
  • 6
  • 78
  • 114
1

--add-drop-database and --databases <database_name> (or --all-databases).

If you use mysqldump --add-drop-database <database_name>, DROP DATABASE and CREATE DATABASE statements will not be added.

Phistrom
  • 113
  • 6
alvosu
  • 8,437
  • 25
  • 22