How to Select a Database in MariaDB on Ubuntu 22.04


In the earlier post, we discussed the different approaches for restarting the MariaDB service on Ubuntu 22.04. Now let’s have a look at the creation and selection of a database in MariaDB on Ubuntu 22.04.

It is essential to select a database in MariaDB for identifying which database is to be used for queries and operations. It ensures data integrity when dealing with multiple databases and improves efficiency by working with specific sets of data. More specifically, without selecting a database, queries, and operations will fail for sure.

This tutorial will discuss:

  • How to Create a Database in MariaDB on Ubuntu 22.04?
  • How to Select a Database in MariaDB on Ubuntu 22.04?

How to Create a Database in MariaDB on Ubuntu 22.04?

Creating databases in MariaDB is necessary for storing and managing structured data efficiently. It offers an organized way to store large amounts of data, ensuring quick and easy access when needed. Therefore, before selecting a database, you must have created it earlier. If you don’t have an existing database, then, follow these steps.

Step 1: Open the Terminal

For launching the terminal, hit “CTRL+ALT+T”:

Step 2: Access the MariaDB Shell

You can access the MariaDB shell by writing the provided command:

mysql -u root -p

Step 3: Create a Database

In MariaDB, a database can be created by using the mentioned command:

CREATE DATABASE linuxgenie;

Note: Here, we created a database named “linuxgenie”.

Database “linuxgenie” has been created successfully.

How to Select a Database in MariaDB on Ubuntu 22.04?

Selecting a database in MariaDB is necessary for specifying which database to interact with. It permits you to manage and organize your data more effectively and perform tasks such as data retrieval, manipulation, and reporting. Additionally, it can improve performance by reducing the amount of unnecessary data being processed.

Now, heading toward the main topic. In this section, we will see how to select a database in MariaDB on Ubuntu 22.04.

Step 1: Verify Database Creation

Utilize the command below to display all created databases in MariaDB:

SHOW DATABASES;

Step 2: Select the Database

As the next step, execute the command below for selecting a specific database:

USE linuxgenie;

Step 3: Verify Database Selection

You can check the name of the selected database by running the below command:

select database();

It can be observed that “linuxgenie” is our selected database.

That was all about selecting a database in MariaDB on Ubuntu 22.04.

Conclusion

Before selecting a database, it is required that it has been created earlier. For creating a database, you need to access the MariaDB shell. To do so, launch the terminal and type “mysql -u root -p”. After that, create a database by typing “CREATE DATABASE linuxgenie;” in the terminal. Now, to select the database we created, utilize the “USE linuxgenie;” command. For verifying the database selection, write “select database();” in the terminal. That’s how you can select a database in MariaDB on Ubuntu 22.04.

Print Friendly, PDF & Email
Categories