Database Reference
In-Depth Information
Creating and dropping databases
When we install MariaDB, we're installing a database server, not a specific database,
and a single MariaDB database server can have several databases inside it. Here's an
analogy that can help us understand this arrangement: a database can be thought of as
a large filing cabinet. The filing cabinet contains a number of drawers and inside each
drawer are files with information. In this analogy, the filing cabinet is a database, the
drawers are tables within the database, and the files are rows of data within the tables.
So what is MariaDB? It's the room the filing cabinet is located in, and it's a large room
so we can put many filing cabinets inside it. When MariaDB is installed, the installer
creates a system database that MariaDB uses to keep track of users and databases
and other housekeeping information. The installer also creates a test database for
experimentation and learning and a read-only database where MariaDB stores
performance statistics. We don't want to use the system database as we could mess up
the entire server if we made a mistake. We can't put data into the statistics database,
called performance_schema , because it is read only. We can use the test database,
but we probably don't want to use it for anything permanent. So one of our first tasks
when we start using MariaDB is to create at least one database for us to use.
Generally, databases are created for specific things or specific applications. For
example, we could have an accounting database for the finance department, a human
resources database for the HR department, and a parts database for the warehouse.
Creating and dropping (deleting) databases are two things that we will do less often
than just about anything else when working with MariaDB. There just isn't much
call for it in day-to-day work. We generally create a database and then use it as long
as it is needed (which could be for years or decades) and then we delete (drop) it.
Thankfully, the commands for creating and dropping a database are very simple, so
they're easy to remember.
Creating a database
As mentioned previously, creating a database is not something we do often. To
create a database in MariaDB, we use the CREATE DATABASE command. The basic
syntax is as follows:
CREATE DATABASE <databasename> ;
If the database already exists when we try to create it, we will receive an error. We
can suppress the error with IF NOT EXISTS .
 
Search WWH ::




Custom Search