Create / Drop database in MySQL
List the Database Present in MySQL
-- Login with Root User
$mysql -u root -p
--List the database present in MySQL
mysql> SHOW DATABASES;
+--------------------+
| Database |
+--------------------+
| information_schema |
| database_name |
| mysql |
| performance_schema |
| sys |
+--------------------+
5 rows in set (0.01 sec)
Create the Database in MySQL
mysql> CREATE DATABASE database_name;
Example:
mysql> CREATE DATABASE test;
Query OK, 1 row affected (0.01 sec)
Error: If database already exists
ERROR 1007 (HY000): Can't create database 'test'; database exists
Solution:
CREATE DATABASE IF NOT EXISTS test;
Drop the Database in MySQL
mysql>DROP DATABASE database_name;
Example:
mysql>DROP DATABASE test;
Query OK, 0 rows affected (0.01 sec)
Error: If database does not exists
ERROR 1008 (HY000): Can't drop database 'test'; database doesn't exist
Solution:
mysql> DROP DATABASE IF EXISTS test;