Sample Header Ad - 728x90

How can I create a mysql database (if it doesn't exist) or replace it (if it exists)?

0 votes
1 answer
5511 views
My dump: mysqldump --host=localhost --user=root --password=whatever --single-transaction --routines --triggers --log-error=error.txt --databases mydatabase > out.sql My restore mysql --host=localhost --user=root --password=whatever -Dtargetdatabasename < out.sql As I am restoring a single database, I need to make sure that if it already exists it is deleted and if it does not exist I must create it (empty) in order to import my dump file without errors. How do I do this, from the cmd console with batch? Thanks Update Solved:
mysql --host=localhost --user=root --password=whatever -e "DROP DATABASE IF EXISTS database_name";
mysql --host=localhost --user=root --password=whatever -e "CREATE DATABASE IF NOT EXISTS database_name";
if someone has a better idea to publish it, to select the answer as correct, otherwise you can vote for close
Asked by acgbox (157 rep)
Aug 25, 2021, 11:04 PM
Last activity: Aug 26, 2021, 11:11 PM