Exporting MariaDB, no DROP DATABASE or CREATE DATABASE

All we need is an easy explanation of the problem, so here it is.

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.

How to solve :

I know you bored from this bug, So we are here to help you! Take a deep breath and look at the explanation of your problem. We have many solutions to this problem, But we recommend you to use the first method because it is tested & true method that will 100% work for you.

Method 1

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.

Note: Use and implement method 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply