How to Install Latest MariaDB Database on Ubuntu 22.04

MariaDB is a free, open-source, and fork of the popular MySQL database system. It is a widely used relational database management system made by the original developers of MySQL. It is specially designed for scalability and mission-critical deployments. By default, the MariaDB package is available in the default repository of all major Linux distributions. At the time of writing this tutorial, the latest version of MariaDB is 10.8. Every major release will be maintained at least 5 years. So MariaDB 10.8.0 will be supported until 2027.

In this tutorial, we will show you how to install MariaDB 10.8 on Ubuntu 22.04 server.

Prerequisites

  • A server running Ubuntu 22.04.
  • A root password is configured on the server.

Add the MariaDB Repository

By default, the latest MariaDB version is unavailable in the Ubuntu 22.04 standard repository. So, you will need to add the MariaDB official repository to your system.

First, install all required dependencies with the following command:

apt-get install software-properties-common gnupg2 -y

Once all the dependencies are installed, import the MariaDB signing key with the following command:

apt-key adv --fetch-keys 'https://mariadb.org/mariadb_release_signing_key.asc'

You should get the following output:

Executing: /tmp/apt-key-gpghome.kGFC5Ag1H8/gpg.1.sh --fetch-keys https://mariadb.org/mariadb_release_signing_key.asc
gpg: requesting key from 'https://mariadb.org/mariadb_release_signing_key.asc'
gpg: key F1656F24C74CD1D8: public key "MariaDB Signing Key <[email protected]>" imported
gpg: Total number processed: 1
gpg:               imported: 1

Next, add the MariaDB repository with the following command:

add-apt-repository 'deb [arch=amd64] http://mariadb.mirror.globo.tech/repo/10.8/ubuntu jammy main'

Once the repository is added, update the repository with the following command:

apt-get update -y

At this point, the MariaDB repository is added and up-to-date. You can now proceed to the next step.

Install and Configure MariaDB

Now, install the latest version of the MariaDB server and client with the following command:

apt-get install mariadb-server mariadb-client -y

After successful installation, start the MariaDB service and enable it to start at system reboot:

systemctl start mariadb
systemctl enable mariadb

Next, you will need to secure the MariaDB installation and set the MariaDB root password. You can do it by running the following script:

mysql_secure_installation

You will be asked to provide your current root password as shown below:

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, and
haven't set the root password yet, you should just press enter here.

Enter current password for root (enter for none): 

Just press Enter. You will be asked to switch to unix_socket authentication as shown below:

OK, successfully used password, moving on...

Setting the root password or using the unix_socket ensures that nobody
can log into the MariaDB root user without the proper authorization.

You already have your root account protected, so you can safely answer 'n'.

Switch to unix_socket authentication [Y/n] Y

Type Y and hit Enter. You will be asked to change the root password as shown below:

Enabled successfully!
Reloading privilege tables..
 ... Success!


You already have your root account protected, so you can safely answer 'n'.

Change the root password? [Y/n] Y

Type Y and hit Enter to change the root password.

New password: 
Re-enter new password: 

Provide your secure password and hit Enter. You should see the following output:

Password updated successfully!
Reloading privilege tables..
 ... Success!


Next, you will be asked to remove anonymous users as shown below:

By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] Y

Type Y and hit Enter to remove the anonymous users. You will be asked to disallow remote root login as shown below:

 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] Y

Type Y and hit Enter. You will be asked to remove a test database as shown below:

 ... Success!

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] Y

Type Y and hit Enter to remove the test database. You will be asked to reload the privileges tables as shown below:

 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] Y

Type Y and hit Enter, you should see the following output:

 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

Verify MariaDB Version

At this point, MariaDB is installed and secured. Next, you will need to verify the installed version of MariaDB.

First, log in to the MariaDB shell with the following command:

mysql -u root -p

Provide your MariaDB root password and hit Enter. Once login, you should see the following output:

Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 31
Server version: 10.8.3-MariaDB-1:10.8.3+maria~jammy mariadb.org binary distribution

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

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

MariaDB [(none)]> 

Run the following command to verify the MariaDB version:

MariaDB [(none)]> SELECT VERSION();

You should get the following output:

+-------------------------------------+
| VERSION()                           |
+-------------------------------------+
| 10.8.3-MariaDB-1:10.8.3+maria~jammy |
+-------------------------------------+
1 row in set (0.000 sec)

Frequently Asked Questions about MariaDB

What is MariaDB?

MariaDB is an open-source relational database management system (RDBMS) that is a fork of MySQL. It was created by the original developers of MySQL after concerns over its acquisition by Oracle. MariaDB is designed to be highly compatible with MySQL, meaning that it supports the same schemas, APIs, and commands as MySQL.

How does MariaDB differ from MySQL?

While MariaDB was originally created as a direct replacement for MySQL, it has since diverged with additional features, new storage engines, and improved performance. MariaDB tends to have more frequent updates and community-driven development compared to MySQL.

Is MariaDB free to use?

Yes, MariaDB is free and open-source, released under the GNU General Public License version 2.

What are the main features of MariaDB?

Key features include its open-source nature, compatibility with MySQL, a variety of storage engines, advanced clustering capabilities, replication, and a strong focus on performance and stability.

Can MariaDB be used as a drop-in replacement for MySQL?

Yes, in most cases, MariaDB can be used as a drop-in replacement for MySQL. It is designed to be binary-compatible with MySQL databases.

How is data stored in MariaDB?

MariaDB uses a variety of storage engines to store data, including InnoDB, MyISAM, and Aria, among others. Each engine has its own advantages and use cases.

Does MariaDB support replication?

Yes, MariaDB supports master-slave and master-master replication, similar to MySQL. It also offers Galera Cluster for synchronous multi-master replication.

What programming languages can interface with MariaDB?

MariaDB can be accessed using most popular programming languages, including PHP, Python, Java, C#, Ruby, and others, usually through MySQL connectors or native drivers.

How does MariaDB handle security?

MariaDB provides robust security features including password hashing, role-based access control, SSL/TLS encryption, and auditing capabilities to ensure data security and compliance.

Is MariaDB suitable for large-scale enterprises?

MariaDB is scalable and robust enough to handle large-scale enterprise applications. It is used by many large organizations and can handle complex databases and high-volume transactions.

How is the performance of MariaDB?

MariaDB is known for its high performance. It has several storage engines and optimizations that can be configured for various types of workloads, enhancing performance.

Does MariaDB support stored procedures?

Yes, MariaDB supports stored procedures and functions, allowing users to encapsulate complex business logic within the database.

Can I migrate my existing MySQL database to MariaDB?

Yes, migrating from MySQL to MariaDB is generally straightforward since MariaDB is designed to be compatible with MySQL databases.

Where can I find documentation and community support for MariaDB?

The official MariaDB website provides comprehensive documentation. Additionally, there are active community forums, Stack Overflow, and other online resources where you can find support and discussions related to MariaDB.

What is the latest version of MariaDB and where can I download it?

The latest version of MariaDB can be found on its official website. It's important to check the website for the most current version and download details.

Conclusion

In this post, we explained how to install the latest MariaDB database on Ubuntu 22.04 server. We also explained how to secure the MariaDB and check the MariaDB version. You can now connect to the MariaDB and start creating a database, user and integrate it with your application.

Share this page:

0 Comment(s)