Check if a database exists in MySQL from the command line

To check if a database exists from the command line in MySQL echo 
the following query and pipe (|) it to the MySQL command line utility:

echo SELECT COUNT(*) as num FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMATA.SCHEMA_NAME="some_database_name"; | mysql --debug-check --user root --host localhost --password some_password

This will return something like the following if it does exist:

num
1

If it does not exist it will return something like:

num
0



comments powered by Disqus