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

To get the current date and time in CodeIgniter, you can use the date() function from PHP, combined with the now() function from the CodeIgniter’s built-in date library.

Here’s an example:

$datestring = 'Year: %Y Month: %m Day: %d - %h:%i %a';
$time = time();

$result = date($datestring, $time);

echo $result;

Or you can use the now() function:

$this->load->helper('date');
echo now();

In this example, the date() function is used to format the current date and time using the $datestring format string, and the now() function is used to return the current date and time as a Unix timestamp. The result is then displayed using echo.

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;

check if a MySQL database exists?

To check if a MySQL database exists, you can use the SHOW DATABASES statement and check if the desired database is in the list of returned databases.

Here’s an example in PHP using the MySQLi extension:


In this example, the SHOW DATABASES statement is executed and the result is stored in the $result variable. The list of returned databases is then looped over and checked against the desired database name. If the database exists, the $db_exists variable is set to true and the result is displayed.

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.

Leave a Comment