Install MySQL | MariaDB Database on Garuda Linux

Posted on 25 views

We’d like to welcome you to our tutorial about setting up MySQL and MariaDB databases on Garuda Linux. MySQL is a relational database management system (RDBMS) that uses SQL (Structured Query Language) queries to perform operations. It’s one of the most widely used languages for accessing and maintaining table records. Under the GNU license, MySQL is open-source and free software. The Oracle Corporation is in favor of it. MariaDB is a free and open source relational database with a SQL interface for data access. GIS and JSON capabilities have been added to MariaDB in recent editions. MariaDB is a MySQL fork that is actively developed by the open source community.

Features of MySQL | MariaDB Database

a.) MySQL Features

Below are MySQL features;

  • It is safe.
  • System for Managing Relational Databases (RDBMS).
  • Architecture of Client/Server.
  • Efficiency of memory.
  • It’s adaptable.
  • Simple to use.
  • Downloading is completely free.
  • High performance.
  • Compatibility with a variety of OS systems.

b.) MariaDB Features

The following are MariaDB features;

  • MariaDB is available under the GPL, LGPL, or BSD licenses.
  • For dealing with different RDBMS data sources, MariaDB provides a variety of storage engines, including high-performance storage engines.
  • MariaDB makes advantage of a well-known and widely used querying language.
  • MariaDB supports a wide range of programming languages and operates on a variety of operating systems.
  • PHP, one of the most popular web development languages, is supported by MariaDB.
  • Galera cluster technology is available from MariaDB.
  • MariaDB also has a number of procedures and commands that aren’t accessible in MySQL, as well as features that have a detrimental influence on performance.

Install MySQL | MariaDB Database on Garuda Linux

1. Install MySQL Database

Follow the steps below to install MySQL database on Garuda Linux.

Step 1. Update System

If possible, we usually recommend starting any program installation with an OS upgrade.

$ sudo pacman -Sy
[sudo] password for frankb:
:: Synchronizing package databases...
 core                                                                      136.1 KiB   233 KiB/s 00:01 [------------------------------------------------------------] 100%
 extra                                                                    1568.3 KiB   767 KiB/s 00:02 [------------------------------------------------------------] 100%
 community                                                                   5.6 MiB   870 KiB/s 00:07 [------------------------------------------------------------] 100%
 multilib                                                                  149.5 KiB   415 KiB/s 00:00 [------------------------------------------------------------] 100%
 chaotic-aur                                                              1362.3 KiB   676 KiB/s 00:02 [------------------------------------------------------------] 100%

Step 2. Install MySQL Database

Run the following command to install MySQL database;

$ sudo pacman -S mysql
:: There are 2 providers available for mysql:
:: Repository extra
   1) mariadb
:: Repository community
   2) percona-server

Enter a number (default=1): 2
resolving dependencies...
looking for conflicting packages...

Packages (2) jemalloc-1:5.2.1-3  percona-server-8.0.25_15-2

Total Download Size:     25.64 MiB
Total Installed Size:  169.74 MiB

:: Proceed with installation? [Y/n] y
:: Retrieving packages...
 percona-server-8.0.25_15-2-x86_64                                          25.64 MiB   152 KiB/s 00:31 [------------------------------------------------------------] 100%
(2/2) checking keys in keyring                                                                        [------------------------------------------------------------] 100%
(2/2) checking package integrity                                                                      [------------------------------------------------------------] 100%
(2/2) loading package files                                                                           [------------------------------------------------------------] 100%
(2/2) checking for file conflicts                                                                     [------------------------------------------------------------] 100%
(2/2) checking available disk space                                                                   [------------------------------------------------------------] 100%
:: Processing package changes...
(1/2) installing jemalloc                                                                             [------------------------------------------------------------] 100%
Optional dependencies for jemalloc
    perl: for jeprof [installed]
(2/2) installing percona-server                                                                       [------------------------------------------------------------] 100%
Optional dependencies for percona-server
    perl-dbd-mysql
:: Running post-transaction hooks...
(1/9) Syncing all file systems...
(2/9) Creating system user accounts...
Creating group mysql with gid 89.
Creating user mysql (MySQL user) with uid 89 and gid 89.
Creating group mysqlrouter with gid 960.
Creating user mysqlrouter (Percona MySQL Router) with uid 960 and gid 960.
(3/9) Reloading system manager configuration...
(4/9) Arming ConditionNeedsUpdate...
(5/9) Foreign/AUR package notification
jack 0.125.0-9
libcanberra-pulse 0.30+2+gc0620e4-3
libopenaptx 0.2.0-1
(6/9) Orphaned package notification...
=> No orphans found.
(7/9) Checking for .pacnew and .pacsave files...
(8/9) Updating pkgfile database...
(9/9) Syncing all file systems...

For efficiency reasons, if you use the Btrfs filesystem, you should disable copy-on-write for the database directory:

sudo chattr +C /var/lib/mysql/

Initialize database server using the commands below:

sudo mysqld --initialize --user=mysql --basedir=/usr --datadir=/var/lib/mysql

Start the mysqld service.

sudo systemctl enable --now mysqld.service

2. Install MariaDB Database Server

Follow the steps below to install MariaDB database on Garuda Linux.

Step 1. Update System

$ sudo pacman -Sy
[sudo] password for frankb:
:: Synchronizing package databases...
 core                                                                      136.1 KiB   233 KiB/s 00:01 [------------------------------------------------------------] 100%
 extra                                                                    1568.3 KiB   767 KiB/s 00:02 [------------------------------------------------------------] 100%
 community                                                                   5.6 MiB   870 KiB/s 00:07 [------------------------------------------------------------] 100%
 multilib                                                                  149.5 KiB   415 KiB/s 00:00 [------------------------------------------------------------] 100%
 chaotic-aur                                                              1362.3 KiB   676 KiB/s 00:02 [------------------------------------------------------------] 100%

Step 2. Install MariaDB Database

Run the following command to install MariaDB database:

$ sudo pacman -S libmariadbclient mariadb mariadb-clients
resolving dependencies...
looking for conflicting packages...
:: mariadb and percona-server are in conflict (mysql). Remove percona-server? [y/N] y

Packages (4) percona-server-8.0.25_15-2 [removal]  mariadb-10.6.3-1  mariadb-clients-10.6.3-1  mariadb-libs-10.6.3-1

Total Download Size:    35.65 MiB
Total Installed Size:  304.24 MiB
Net Upgrade Size:      136.33 MiB

:: Proceed with installation? [Y/n] y

The above output shows that the conflicting packages are removed i.e percona-server are in conflict used to install mysql.

For efficiency reasons, if you use the Btrfs filesystem, you should disable copy-on-write for the database directory:

sudo chattr +C /var/lib/mysql/

Initialize database server using the commands below:

$ sudo mysql_install_db --user=mysql --basedir=/usr --datadir=/var/lib/mysql
Installing MariaDB/MySQL system tables in '/var/lib/mysql' ...
OK

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system


Two all-privilege accounts were created.
One is [email protected], it has no password, but you need to
be system 'root' user to connect. Use, for example, sudo mysql
The second is [email protected], it has no password either, but
you need to be the system 'mysql' user to connect.
After connecting you can set the password, if you would need to be
able to connect as any of these users with a password and without sudo

See the MariaDB Knowledgebase at https://mariadb.com/kb or the
MySQL manual for more instructions.

You can start the MariaDB daemon with:
cd '/usr' ; /usr/bin/mysqld_safe --datadir='/var/lib/mysql'

You can test the MariaDB daemon with mysql-test-run.pl
cd '/usr/mysql-test' ; perl mysql-test-run.pl

Please report any problems at https://mariadb.org/jira

The latest information about MariaDB is available at https://mariadb.org/.
You can find additional information about the MySQL part at:
https://dev.mysql.com
Consider joining MariaDB's strong and vibrant community:
https://mariadb.org/get-involved/

Start and enable mariadb service:

sudo systemctl enable --now mariadb.service

Securing Mysql | MariaDB Database Server

You can now protect your database server by following these steps:

$ sudo mysql_secure_installation

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): 
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 authorisation.

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

Switch to unix_socket authentication [Y/n] y
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
New password: 
Re-enter new password:  
Password updated successfully!
Reloading privilege tables..
 ... Success!


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

Creating Database Mysql | MariaDB Database Server

As the root user, launch MySQL Shell:

$ mysql -u root -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 13
Server version: 10.6.3-MariaDB Arch Linux

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)]> 

Create database by the name my_db:

create database my_db;

Create user by the name user_a:

create user user_1@localhost identified by 'StrongPassw0rd';

Remember to replace ‘StrongPassw0rd‘ with your password.

Now let’s grant all the privileges to the my_db database with the following command:

grant all privileges on my_db.* to 'user_1'@'localhost';

We can now flush the privileges using the following command:

MariaDB [(none)]>  flush privileges;

Issue the following command to check the databases:

MariaDB [(none)]> SHOW DATABASES;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| my_db              |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
5 rows in set (0.003 sec)

Drop a database my_db:

DROP DATABASE my_db;

Exit Mysql | MariaDB database:

MariaDB [(none)]> exit;
Bye

Conclusion

Thank you for reading this tutorial on how to install MySQL | MariaDB Database on Garuda Linux. We hope you found it useful.

coffee

Gravatar Image
A systems engineer with excellent skills in systems administration, cloud computing, systems deployment, virtualization, containers, and a certified ethical hacker.