Working with MariaDB – basic command

So you have installed and logged in into MariaDB.
What next?
You probably get the following screen:


Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 47
Server version: 10.0.25-MariaDB-0ubuntu0.16.04.1 Ubuntu 16.04

Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]>

One of the first command you can use is SHOW DATABASES;
This command is used to show the current databases on the server.
If this is the first time anyone logged into MariaDB then you probably get the following output:


Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 47
Server version: 10.0.25-MariaDB-0ubuntu0.16.04.1 Ubuntu 16.04

Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]>  SHOW DATABASES;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
+--------------------+
3 rows in set (0.00 sec)

This 3 databases has already been created for you.
The next thing you will want to do is to create your own database, for this you should run CREATE DATABASE <database_name>;
So for example lets say we want to create the first db with the name firstDB.
We should just run:


MariaDB [(none)]> CREATE DATABASE firstDB;
Query OK, 1 row affected (0.00 sec)

Now that the database has been created, we should start using it.
First thing lest check if we are using any database currently, we can do this with the command SELECT database();

Since this is the first time anyone is using the DB, you probably will see the following:


MariaDB [(none)]> SELECT database();
+------------+
| database() |
+------------+
| NULL       |
+------------+
1 row in set (0.00 sec)

And that mean, you are currently not using any database.
We can use the “use” command to select database, it very easy USE <databaseName>;
So lets select firstDB.


MariaDB [(none)]> USE firstDB;
Database changed

Now the database has been change to firstDB.

Advertisements

One thought on “Working with MariaDB – basic command

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s