Definition of MariaDB Select Database
MariaDB provides different clauses to the user to perform a different operation as per requirement, so select is the one type of clause. Basically select is used to retrieve the data from the database server. When we use the select database command it retrieves the current database name that is in use, which means it is useful to check current database name. Selecting a database is another concept when we need to select a database at that time we use USE keyword to select a specific database. So select a database and use a database is totally different but it performs similar functions related to the database. We can perform different operations on databases by using select clauses.
Syntax:
select database();
Explanation:
In the above syntax, we use the select clause with a database function as shown in the above statement, here select clause retrieves the current database name from the MariaDB server and database function is used to indicate the name of the database.
How to Select Database in MariaDB?
Let’s see how the select database works in MariaDB as follows.
Basically, the select clause is used to retrieve data or we can say records, table, and database from the MariaDB server that means as per user requirement we can use a select clause. Each select expression shows what type of data we need to retrieve from the database or server.
After execution of the select database command it returns the current database name that is the default database name otherwise it returns the null.
We can also use SCHEMA () as a synonym for the DATABASE () both commands perform the same function.
Examples
Let’s see the different examples of select databases as follows.

4.5 (9,224 ratings)
View Course
First, connect to the MariaDB server by using the client program, so we required a password for that purpose. Then use the following statement to see the current database.
select database();
Explanation:
In the above example, we use a select clause followed by a database function as shown in the above statement. Suppose users need to see what the name of the current database is, so that time we can use the above statement and return the current database name. The final output of the show databases queries we illustrate by using the following snapshot.
Example: If we don’t use any database.
select database();
Explanation:
In the above example, we use a select clause followed by a database function as shown in the above statement. Suppose the user wants to see the name of the current database so that times we can use the above statement but return the null value because we can’t use any database. The final output of the show databases queries we illustrate by using the following snapshot.
Example
Suppose users need to switch to another database and then need to check the current database name at that time we use the following statement.
First we need to use the different database as follows
First, we need to check all available databases from the server as follows.
show databases;
Explanation:
By using the above statement we list all databases from the MariaDB server then we use any one of them. The final output of the show databases queries we illustrate by using the following snapshot.
Syntax:
use database name;
Explanation:
In the above syntax use database command is used to select a specific database from the MariaDB server, here the database name is used to specify the database name that we need to use as the current database.
Example
use demo;
Explanation:
With the help of the above statement, we switch the database that means one database to another database; here demo is the database name that we need to use for our workspace. The final output of the show databases queries we illustrate by using the following snapshot.
After switching databases we again perform a select database command as follows.
select database();
Explanation:
See hereafter switching the database name we execute select database () command to check current database name, here we changed database sample to demo. The final output of the show databases queries we illustrate by using the following snapshot.
Now see how the schema works as follows.
select schema();
Explanation:
In the above example, we use a select clause to fetch the default database or current database of our workspace. Here select clause followed by schema keyword the schema is work similar to select database of our current workspace. The final output of the show databases queries we illustrate by using the following snapshot.
Now let’s see a different example of a select database as follows.
Suppose we created a new database name office and we need to use it for the current workspace, so first, we need to create the database by using the following statement as follows.
create database office;
Explanation:
In the above example, we used create database statement to create a new database here we created a new database name as office. The final output of the show databases query we illustrate by using the following snapshot.
Now see the created database by using the following statement as follows.
show databases;
Explanation:
In this example, we use the show databases command to list all databases from the MariaDB server. The final output of the show databases queries we illustrate by using the following snapshot.
Now use the created database for our current workspace by using the following statement as follows.
use office;
Explanation:
When we execute the above statement then it shows the database is changed because of the use command. The final output of the show databases queries we illustrate by using the following snapshot.
Finally, now we can see the current database name by using the following statement as follows.
select database();
Explanation:
When we execute the above statement, which contains the select clause followed by the database keyword it is used to see the current database of our workspace. The final output of the show databases queries we illustrate by using the following snapshot.
Conclusion
We hope from this article you have understood about the MariaDB select database. From this article, we have learned the basic syntax of select databases and we also see different examples of select databases. From this article, we learned how and when we use MariaDB select database.
Recommended Articles
This is a guide to MariaDB Select Database. Here we discuss the definition, How to Select Database in MariaDB? and examples with code implementation. You may also have a look at the following articles to learn more –