mysql -u root -pEnter the administrator password you set up during installation. You will be given a MySQL/MariaDB prompt.
CREATE DATABASE new_database;
Query OK, 1 row affected (0.00 sec)To avoid errors in the event that the database name we've chosen already exists, use the following command:
CREATE DATABASE IF NOT EXISTS new_database;
Query OK, 1 row affected, 1 warning (0.01 sec)The warning indicates that the database already existed and no new database was created.
ERROR 1007 (HY000): Can't create database 'other_database'; database exists
SHOW DATABASES;
+--------------------+ | Database | +--------------------+ | information_schema | | mysql | | new_database | | other_database | | performance_schema | +--------------------+ 5 rows in set (0.00 sec)The "information_schema", "performance_schema", and "mysql" databases are set up by default in most cases and should be left alone unless you know what you are doing.
SELECT database();
+------------+ | database() | +------------+ | NULL | +------------+ 1 row in set (0.01 sec)We have received a result of "null". This means that no database is currently selected.
USE new_database;
Database changedWe can see that the database has been selected by re-issuing the command we ran previously:
SELECT database();
+--------------+ | database() | +--------------+ | new_database | +--------------+ 1 row in set (0.00 sec)
DROP DATABASE new_database;
Query OK, 0 rows affected (0.00 sec)This operation cannot be reversed! Make certain you wish to delete before pressing enter!
DROP DATABASE new_database;
ERROR 1008 (HY000): Can't drop database 'new_database'; database doesn't existTo prevent this error, and ensure that the command executes successfully regardless of if the database exists, call it with the following syntax:
DROP DATABASE IF EXISTS new_database;
Query OK, 0 rows affected, 1 warning (0.00 sec)The warning indicates that the database did not exist, but the command executes successfully anyways.
Article ID: 186
Created On: Thu, Dec 26, 2013 at 10:26 PM
Last Updated On: Sun, Jan 5, 2014 at 8:44 PM
Authored by: ASPHostServer Administrator [asphostserver@gmail.com]
Online URL: http://faq.asphosthelpdesk.com/article.php?id=186