mysql check if database exists – 2 ways to check if mysql database exists

mysql check if database exists: SHOW DATABASES LIKE ‘dbname’; If you have database with the name ‘dbname’ doesn’t exist, you get an empty collumn set. If it does exist, you get single row.

mysql check if database exists

The schema_name command is used to check if a MySQL database exists or not. check it out by executing the following query: Checks whether or not the database exists on the server.

How to check if mysql database exists?

SELECT SCHEMA_NAME
  FROM INFORMATION_SCHEMA.SCHEMATA
 WHERE SCHEMA_NAME = 'pakainfo_v1'

CREATE DATABASE IF NOT EXISTS pakainfo_v1;

Don’t Miss : Sql Check If Table Exists

show command

show databases;

OR

mysql> show databases;

mysql> use pakainfo_v1;
Database changed

//OR

mysql> show tables;

desc pakainfo_v1;
mysql> desc modifydatatype;

How to check if a MySQL database exists?

Phase 1 − The database exists.

mysql> select schema_name from information_schema.schemata where schema_name = 'pakainfo_v1';

Phase 2 − The database does not exist.

mysql> select schema_name from information_schema.schemata where schema_name = 'pakainfo_v2';
Empty set (0.00 sec)

python mysql check if database exists

CREATE DATABASE IF NOT EXISTS DBName;

I hope you get an idea about mysql check if database exists.
I would like to have feedback on my infinityknow.com.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.