Install MariaDB 10 on Debian 12

|
Last Updated:
|
|

Follow through this guide to learn how to install MariaDB 10 on Debian 12. “MariaDB 10 is the new major release series of MariaDB. It ships with several entirely new features and improvements.

Installing MariaDB 10 on Debian 12

Run System Update

Assuming that you are installing MariaDB 10 on a newly installed Debian 12, update and upgrade your system packages.

apt update

Install MariaDB 10

One of the easiest ways to install MariaDB is via the use of their MariaDB package repositories.

The default repos for Debian 10/Debian 12 do provide MariaDB 10 packages.

apt show mariadb-server

Package: mariadb-server
Version: 1:10.11.3-1
Priority: optional
Section: database
Source: mariadb
Maintainer: Debian MySQL Maintainers 
Installed-Size: 55.2 MB
Provides: virtual-mysql-server
Pre-Depends: adduser (>= 3.40), debconf, mariadb-common (>= 1:10.11.3-1)
...

Thus, install MariaDB 10 by running the command below;

apt install mariadb-server

Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
  galera-4 gawk libcgi-fast-perl libcgi-pm-perl libconfig-inifiles-perl libdaxctl1 libdbd-mariadb-perl libdbi-perl libfcgi-bin libfcgi-perl libfcgi0ldbl
  libhtml-template-perl libmariadb3 libndctl6 libpmem1 libsigsegv2 libterm-readkey-perl liburing2 mariadb-client mariadb-client-core mariadb-common
  mariadb-plugin-provider-bzip2 mariadb-plugin-provider-lz4 mariadb-plugin-provider-lzma mariadb-plugin-provider-lzo mariadb-plugin-provider-snappy mariadb-server-core
  mysql-common pv rsync socat
Suggested packages:
  gawk-doc libmldbm-perl libnet-daemon-perl libsql-statement-perl libipc-sharedcache-perl mailx mariadb-test netcat-openbsd doc-base python3-braceexpand
The following NEW packages will be installed:
  galera-4 gawk libcgi-fast-perl libcgi-pm-perl libconfig-inifiles-perl libdaxctl1 libdbd-mariadb-perl libdbi-perl libfcgi-bin libfcgi-perl libfcgi0ldbl
  libhtml-template-perl libmariadb3 libndctl6 libpmem1 libsigsegv2 libterm-readkey-perl liburing2 mariadb-client mariadb-client-core mariadb-common
  mariadb-plugin-provider-bzip2 mariadb-plugin-provider-lz4 mariadb-plugin-provider-lzma mariadb-plugin-provider-lzo mariadb-plugin-provider-snappy mariadb-server
  mariadb-server-core mysql-common pv rsync socat
0 upgraded, 32 newly installed, 0 to remove and 0 not upgraded.
Need to get 18.9 MB of archives.
After this operation, 194 MB of additional disk space will be used.
Do you want to continue? [Y/n] y

Verify the MariaDB installed version

MariaDB 10 deprecates the use of mysql command line tool and replaces it with mariadb.

As much as you can still be able to use mysql command, you will get some deprecation warnings.

To check the version of installed MariaDB, run the command below;

mariadb -V
mariadb  Ver 15.1 Distrib 10.11.3-MariaDB, for debian-linux-gnu (x86_64) using  EditLine wrapper

Running MariaDB 10 on Debian 12

Upon installation, MariaDB is started and enabled to run on system boot;

systemctl status mariadb

● mariadb.service - MariaDB 10.11.3 database server
     Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; preset: enabled)
     Active: active (running) since Wed 2023-06-14 00:57:58 EAT; 32s ago
       Docs: man:mariadbd(8)
             https://mariadb.com/kb/en/library/systemd/
   Main PID: 8148 (mariadbd)
     Status: "Taking your SQL requests now..."
      Tasks: 14 (limit: 2285)
     Memory: 92.3M
        CPU: 435ms
     CGroup: /system.slice/mariadb.service
             └─8148 /usr/sbin/mariadbd

Jun 14 00:57:57 bookworm mariadbd[8148]: 2023-06-14  0:57:57 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
Jun 14 00:57:57 bookworm mariadbd[8148]: 2023-06-14  0:57:57 0 [Warning] You need to use --log-bin to make --expire-logs-days or --binlog-expire-logs-seconds work.
Jun 14 00:57:57 bookworm mariadbd[8148]: 2023-06-14  0:57:57 0 [Note] Server socket created on IP: '127.0.0.1'.
Jun 14 00:57:57 bookworm mariadbd[8148]: 2023-06-14  0:57:57 0 [Note] InnoDB: Buffer pool(s) load completed at 230614  0:57:57
Jun 14 00:57:57 bookworm mariadbd[8148]: 2023-06-14  0:57:57 0 [Note] /usr/sbin/mariadbd: ready for connections.
Jun 14 00:57:57 bookworm mariadbd[8148]: Version: '10.11.3-MariaDB-1'  socket: '/run/mysqld/mysqld.sock'  port: 3306  Debian 12
Jun 14 00:57:58 bookworm systemd[1]: Started mariadb.service - MariaDB 10.11.3 database server.
Jun 14 00:57:58 bookworm /etc/mysql/debian-start[8166]: Upgrading MySQL tables if necessary.
Jun 14 00:57:58 bookworm /etc/mysql/debian-start[8177]: Checking for insecure root accounts.
Jun 14 00:57:58 bookworm /etc/mysql/debian-start[8181]: Triggering myisam-recover for all MyISAM tables and aria-recover for all Aria tables

You can manage the service via systemctl command.

For example, to start MariaDB service;

systemctl start mariadb

For example, to restart MariaDB service;

systemctl restart mariadb

To stop the service;

systemctl stop mariadb

Disable the service from running on system boot;

systemctl disable mariadb

Securing MariaDB 10

MariaDB comes with a default security script, mariadb-secure-installation that is used to improve the security of MariaDB installation by:

  • Setting the password for root accounts (if need be).
  • Disabling remote root login to the databases.
  • Removing anonymous-user accounts.
  • Removing the test database, which by default can be accessed by anonymous users.

Simply run the command below to launch the script.

mariadb-secure-installation

MariaDB Authentication

The new installations of MariaDB have two secure accounts are created during the installation.

The accounts are root@localhost and mysql@localhost.

Both accounts uses either of the unix_socket and the mysql_native_password authentication plugins.

unix_socket authentication plugin allows a system root user or a user with sudo rights to login as root@locahost to MariaDB database without a password.

With unix_socket authentication plugin, while being a root user, you can simply login by running either of the commands below;

mariadb

or

mariadb -u root

Even if you run, mariadb -u root -p, and press ENTER for blank password, you will still login.

As a user with sudo rights, prefix the commands above with sudo.

For example, you can login as mysql user;

sudo -u mysql mariadb

Enable MariaDB password Authentication

With the two privileged accounts, root@localhost and mysql@localhost, anyone with access to it can login to MariaDB.

It is not recommended to leave such user accounts with no password and all privileges, as this can pose a significant security risk to your database.

The two accounts above uses mysql_native_password plugin by default;

mariadb
select User,Host,plugin from mysql.user;

+-------------+-----------+-----------------------+
| User        | Host      | plugin                |
+-------------+-----------+-----------------------+
| mariadb.sys | localhost | mysql_native_password |
| root        | localhost | mysql_native_password |
| mysql       | localhost | mysql_native_password |
+-------------+-----------+-----------------------+
3 rows in set (0.002 sec)

MariaDB [(none)]>

The mysql_native_password plugin is used as a failover for the unix_socket plugin. Even if you have setup a password using MariaDB secure installation script, you can still login as those accounts without a password.

show grants for root@localhost;

+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Grants for root@localhost                                                                                                                                                 |
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO `root`@`localhost` IDENTIFIED VIA mysql_native_password USING '*9C6C35530EE4427B07D2FA4F9E119C3915D18940' OR unix_socket WITH GRANT OPTION |
| GRANT PROXY ON ''@'%' TO 'root'@'localhost' WITH GRANT OPTION                                                                                                             |
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
2 rows in set (0.000 sec)

MariaDB [(none)]>
show grants for mysql@localhost;

+------------------------------------------------------------------------------------------------------------------------------------------+
| Grants for mysql@localhost                                                                                                               |
+------------------------------------------------------------------------------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO `mysql`@`localhost` IDENTIFIED VIA mysql_native_password USING 'invalid' OR unix_socket WITH GRANT OPTION |
+------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.000 sec)

MariaDB [(none)]>

As you can see above, we had already set the password for root user using the mysql_secure_installation command. But mysql user account has invalid password.

Thus, enable password authentication.

ALTER USER root@localhost identified by 'myStr0nP@ssW0rd';
ALTER USER mysql@localhost identified by 'myStr0nP@ssW0rd2';
flush privileges;
quit

This re-enables the MariaDB password authentication and hence, you can now login as non root or non sudo user.

mariadb

Or;

sudo -u mysql mariadb

Sample output;

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

Provide a password to be able to login;

mariadb -u root -p

Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 37
Server version: 10.11.3-MariaDB-1 Debian 12

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

Set Native Password Authentication Method as Default

When you set the password above, it completely disables unix_socket authentication plugin and instead use the msqyl_native_password authentication method;

show grants for root@localhost;

+----------------------------------------------------------------------------------------------------------------------------------------+
| Grants for root@localhost                                                                                                              |
+----------------------------------------------------------------------------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO `root`@`localhost` IDENTIFIED BY PASSWORD '*73E1DDB4DA8B34D3080B082A8DFC863A56285DD4' WITH GRANT OPTION |
| GRANT PROXY ON ''@'%' TO 'root'@'localhost' WITH GRANT OPTION                                                                          |
+----------------------------------------------------------------------------------------------------------------------------------------+
2 rows in set (0.000 sec)

MariaDB [(none)]>
show grants for mysql@localhost;

+-----------------------------------------------------------------------------------------------------------------------------------------+
| Grants for mysql@localhost                                                                                                              |
+-----------------------------------------------------------------------------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO `mysql`@`localhost` IDENTIFIED BY PASSWORD '*4C8C1832BBF14A360C2F70EA14CBD912AE0AF280' WITH GRANT OPTION |
+-----------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.000 sec)

MariaDB [(none)]>

That marks the end of our guide on installing MariaDB 10 on Debian 12.

Other Tutorials

You can check our other MySQL/MariaDB related tutorials.

SUPPORT US VIA A VIRTUAL CUP OF COFFEE

We're passionate about sharing our knowledge and experiences with you through our blog. If you appreciate our efforts, consider buying us a virtual coffee. Your support keeps us motivated and enables us to continually improve, ensuring that we can provide you with the best content possible. Thank you for being a coffee-fueled champion of our work!

Photo of author
Kifarunix
Linux Certified Engineer, with a passion for open-source technology and a strong understanding of Linux systems. With experience in system administration, troubleshooting, and automation, I am skilled in maintaining and optimizing Linux infrastructure.

Leave a Comment