Exporting MariaDB, no DROP DATABASE or CREATE DATABASE

mariadb

I'm using MariaDB 10.5, If I do the following:

"C:/Program Files (x86)/MariaDB 10.5/bin/mysqldump" --skip-comments --compact --lock-tables=false --add-drop-database --host=localhost --user=trainer --password=PASSWORD training > C:/Users/splatten/Documents/TrainerS1D5.sql

In the command I've specified training which is the database to export and it exports the tables, data and stored procedures from this database.

It looks like it should be working, but it doesn't include either DROP DATABASE or CREATE DATABASE.

Best Answer

The DROP DATABASE and CREATE DATABASE commands are generally not part of a default dump operation. You will need to add one item to your command:

--databases or -B:

This will allow you to dump several databases if you wish, but you can also use this option if you would like to have CREATE DATABASE and USE inlaced in the output before each database is defined.

A note about --add-drop-database:

As one would expect, this option will add a DROP DATABASE statement before each CREATE DATABASE. This option is generally used alongside the --all-databases or —databases options as there is no CREATE DATABASE statements written without one of these options specified.

So, with this in mind, your command would look like this:

C:\Program Files (x86)\MariaDB 10.5\bin\mysqldump" --skip-comments --compact --lock-tables=false --add-drop-database --host=localhost --user=trainer --password=PASSWORD --databases training > C:\Users\splatten\Documents\TrainerS1D5.sql

Note: I'm not sure if the forward slashes you used in the command were intentional or not. I've replaced them with backslashes as Windows generally requires. Feel free to switch them back if this is in error.

Related Question