Delete Docker MySQL/MariaDB Database in a one-liner

I’ve been using the Bitnami MariaDB Docker Container when testing it with Ghost.

Rather than nuke-and-pave, starting over with the Database volume, just run a one-liner to delete the database as you go about testing:

  • The space that precedes the command is intended, for security.
  • Yes, not having a space after the -p parameter before providing the actual password is correct.

If you were to remove the IF EXISTS conditional, you’ll get a response from mysql:

docker exec --user root -t CONTAINER_ID_HERE /opt/bitnami/mariadb/bin/mysql -uroot -pPASSWORD_GOES_HERE -e 'DROP DATABASE bitnami_ghost;'

ERROR 1008 (HY000) at line 1: Can't drop database 'bitnami_ghost'; database doesn't exist


  • +

© 2021. All rights reserved.