0

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.

1 Answer 1

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.

4
  • Thank you, now I have the CREATE DATABASE in the output, but DROP DATABASE IF EXISTS if there but commented out, how can I get that enabled by default?
    – SPlatten
    Jul 26, 2021 at 12:29
  • With regard to the slashes, I'm developing with Qt and the slashes were put in by internal Qt functions, they work.
    – SPlatten
    Jul 26, 2021 at 12:41
  • 1
    If you have a line that looks like this: /*!40000 DROP DATABASE IF EXISTS training */;, then it's not commented out. The number is a version marker for mysql in a /*!<version> <command> */ format, and will run if the internal mysql version is greater than <version>. 40000 would be MySQL 4.0 👍🏻
    – matigo
    Jul 26, 2021 at 12:41
  • Thank you, learn something new everyday.
    – SPlatten
    Jul 26, 2021 at 12:42

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.