Skip to content
Advertisement

Check if mysql database exists, perform action based on result

Is it possible from within a bash script to check if a mysql database exists. Depending on the result then perform another action or terminate the script?

Advertisement

Answer

Example script (Thanks to Bill Karwin for the --user and --password comment!):

JavaScript

These are what the commands look like when run at a prompt:

JavaScript

If no DB exists, the output will look like this:

JavaScript

Then, parse the output and do what you need to based on if it exists or not!

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement