DEV Community

Dhimas Kirana
Dhimas Kirana

Posted on

How to Install MySQL / MariaDB on Linux Ubuntu

Hello, dev.. ๐Ÿ‘‹

In this tutorial, I want to share how to install MySQL or MariaDB on Linux Ubuntu. The Linux Iโ€™m currently using is Ubuntu 22.04 LTS, so if your Linux OS is the same, you can follow this tutorial.

MySQL / MariaDB

In this tutorial, we will install MariaDB, but you need to know that MariaDB and MySQL are similar. Because MariaDB is a development of the free and open-source version of MySQL after MySQL was acquired by the Oracle company. MariaDB was developed by the original MySQL developer. In terms of performance, MariaDB is faster and more efficient than MySQL.

Install MariaDB

Before starting the installation, make sure to update your OS system first.

sudo apt update
Enter fullscreen mode Exit fullscreen mode

Then install MariaDB server using the following command

sudo apt install mariadb-server
Enter fullscreen mode Exit fullscreen mode

Wait until the installation process is complete. Then to check whether MariaDB is running, check with the following command

sudo systemctl status mariadb
Enter fullscreen mode Exit fullscreen mode

MariaDB Configuration

After MariaDB has been successfully installed, the next step is to configure MariaDB. Run the following command

sudo mysql_secure_installation
Enter fullscreen mode Exit fullscreen mode

Then when Enter current password for root (enter for none) appears: just click enter, because we havenโ€™t set a password yet.

Then the question appears Change the root password? [Y/n] Letโ€™s just choose Y. We will change the root account password. Type a new password and retype the new password. So the result is like this.

Change the root password? [Y/n] Y
New password: 
Re-enter new password: 
Password updated successfully!
Reloading privilege tables..
... Success!
Enter fullscreen mode Exit fullscreen mode

Continue the process until reloading privileges.

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] y
... 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!
Enter fullscreen mode Exit fullscreen mode

At this point, it means that MariaDB has been successfully configured.

MariaDB Access

To access, you can use the following command

mysql -u root -p
Enter fullscreen mode Exit fullscreen mode

To create a view of all databases with the following command

show databases;
Enter fullscreen mode Exit fullscreen mode

Donโ€™t forget the semicolon if you access using the MariaDB command line.

Then to create a database use the following command

create database database_name;
Enter fullscreen mode Exit fullscreen mode

For an example, see the following image

MariaDB Ubuntu 22.04

Good luck ๐Ÿป

Top comments (0)