EDUCBA Logo

EDUCBA

MENUMENU
  • Explore
    • EDUCBA Pro
    • PRO Bundles
    • Featured Skills
    • New & Trending
    • Fresh Entries
    • Finance
    • Data Science
    • Programming and Dev
    • Excel
    • Marketing
    • HR
    • PDP
    • VFX and Design
    • Project Management
    • Exam Prep
    • All Courses
  • Blog
  • Enterprise
  • Free Courses
  • Log in
  • Sign Up
Home Software Development Software Development Tutorials MariaDB Tutorial MariaDB Select Database
 

MariaDB Select Database

Sohel Sayyad
Article bySohel Sayyad
EDUCBA
Reviewed byRavi Rathore

Updated June 2, 2023

MariaDB Select Database

 

 

Definition of MariaDB Select Database

MariaDB provides different clauses to the user to perform a different operation as per requirement, so select 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 the current database name. Selecting a database is another concept when we need to select a database at that time, we use the USE keyword to select a specific database. So selecting and using 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.

Watch our Demo Courses and Videos

Valuation, Hadoop, Excel, Mobile Apps, Web Development & many more.

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 the 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.

The select clause is used to retrieve data, or we can say records, table, and database from the MariaDB server means that we can use a select clause as per user requirement. 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.

First, connect to the MariaDB server using the client program, so we required a password. 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 the current database name 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.

MariaDB Select Database 1

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.

MariaDB Select Database 2

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 and then use any of them. The final output of the show databases queries we illustrate by using the following snapshot.

MariaDB Select Database 3

Syntax:

use database name;

Explanation:

In the above syntax, the 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 we need to use as the current database.

Example

use demo;

Explanation:

With the help of the above statement, we switch the database, which 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.

MariaDB Select Database 4

After switching databases, we again perform a select database command as follows.

select database();

Explanation:

See hereafter switching the database name, we execute the select database () command to check the current database name, here, we changed the database sample to demo. The final output of the show databases queries we illustrate by using the following snapshot.

database

Now see how the schema works as follows.

select schema();

Explanation:

In the above example, we use a select clause to fetch our workspace’s default database or current database. Here select clause followed by the schema keyword works similarly to a select database of our current workspace. The final output of the show databases queries we illustrate by using the following snapshot.

schema sample

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 to create a database statement to create a new database here, we created a new database name, office. The final output of the show databases query we illustrate by using the following snapshot.

create DB Office

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.

database 1

Now use the created database for our current workspace by using the following statement as follows.

use office;

Explanation:

When executing the above statement, 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.

database changed

Finally, we can now see the current database name by using the following statement.

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.

database office

Conclusion

We hope from this article you have understood about the MariaDB select database. This article taught us the basic syntax of special databases and see different examples of select databases. This article taught us how and when to use MariaDB select database.

Recommended Articles

We hope that this EDUCBA information on the “MariaDB Select Database” was beneficial to you. You can view EDUCBA’s recommended articles for more information.

  1. MariaDB AUTO_INCREMENT
  2. MaxScale in MariaDB
  3. MariaDB UPDATE 
  4. MariaDB Commands

Primary Sidebar

Footer

Follow us!
  • EDUCBA FacebookEDUCBA TwitterEDUCBA LinkedINEDUCBA Instagram
  • EDUCBA YoutubeEDUCBA CourseraEDUCBA Udemy
APPS
EDUCBA Android AppEDUCBA iOS App
Blog
  • Blog
  • Free Tutorials
  • About us
  • Contact us
  • Log in
Courses
  • Enterprise Solutions
  • Free Courses
  • Explore Programs
  • All Courses
  • All in One Bundles
  • Sign up
Email
  • [email protected]

ISO 10004:2018 & ISO 9001:2015 Certified

© 2025 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

By continuing above step, you agree to our Terms of Use and Privacy Policy.
*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

EDUCBA Login

Forgot Password?

🚀 Limited Time Offer! - 🎁 ENROLL NOW