Database Reference
In-Depth Information
Here are some examples:
CREATE DATABASE my_database;
CREATE DATABASE IF NOT EXISTS my_database;
The previous two commands are equivalent if the database does not exist. If the
database does exist, the first command will exit with an error and the second
command will do nothing.
Full documentation of the CREATE DATABASE command is available at
https://mariadb.com/kb/en/create-database/ .
Dropping a database
As mentioned before, it isn't often that we need to remove or delete a database, but
when we do, we use the DROP command. The basic syntax is as follows:
DROP DATABASE <databasename>;
If the named database doesn't exist when we try to drop it, we will receive an error.
We can suppress the error with IF EXISTS .
Here are a couple of examples that drop the database we just created:
DROP DATABASE my_database;
DROP DATABASE IF EXISTS my_database;
The preceding two commands are equivalent if the database my_database exists. If
the database does not exist, the first command will exit with an error and the second
command will do nothing.
When dropping a database, user privileges for the database are
not removed. We need to revoke them manually, or drop the user
entirely; otherwise, if or when the database is recreated the user will
still have the privileges. See Chapter 4 , User Account Management , for
information on managing users and their privileges.
Complete documentation of the DROP DATABASE command is available at
https://mariadb.com/kb/en/drop-database/ .
 
Search WWH ::




Custom Search