MariaDB on CentOS is a free, and open source database management system managed by the parent companies – MariaDB Corporation AB and MariaDB Foundation. It has many in-built features including, storage engines, improved security systems, and more. It is an upgraded version of MySQL compatible with all operating systems, such as Windows, Linux, etc. It is written in multiple languages, including Perl, C, bash, and C++. It offers faster caching and supports native non-blocking operations.
MariaDB Server Features
Free and open-source software distributed under the GPL license.
Offers stability, faster speed, and performance.
Compared to MySQL, MariaDB supports a lot of storage engines.
Switch to MariaDB is simple and easier.
Offers better user support for both beginner and experienced users.
In this post, we will show you how to install MariaDB server on CentOS 8.
By Default, the MariaDB package is not included in the Cent OS 8 default repo. So you will need to create a repo for MariaDB. You can create it with the following command:
nano /etc/yum.repos.d/mariadb.repo
Add the following lines:
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.5/centos8-amd64
module_hotfixes=1
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
Save and close the file then update the repo cache with the following command:
You can now install the MariaDB server by running the following command:
dnf install mariadb-server -y
Once the MariaDB is installed, you will need to start the MariaDB service and enable it to start at system reboot. You can do it with the following command:
systemctl start mariadb
systemctl enable mariadb
You can now verify the status of the MariaDB service using the following command:
systemctl status mariadb
You should see the following output:
● mariadb.service - MariaDB 10.5.12 database server
Loaded: loaded (/usr/lib/systemd/system/mariadb.service; disabled; vendor preset: disabled)
Drop-In: /etc/systemd/system/mariadb.service.d
└─migrated-from-my.cnf-settings.conf
Active: active (running) since Sat 2021-09-25 04:19:50 EDT; 6s ago
Docs: man:mariadbd(8)
https://mariadb.com/kb/en/library/systemd/
Process: 3917 ExecStartPost=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
Process: 3895 ExecStartPre=/bin/sh -c [ ! -e /usr/bin/galera_recovery ] && VAR= || VAR=`cd /usr/bin/..; /usr/bin/galera_recovery`; [ $? -e>
Process: 3893 ExecStartPre=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
Main PID: 3905 (mariadbd)
Status: "Taking your SQL requests now..."
Tasks: 11 (limit: 12524)
Memory: 71.9M
CGroup: /system.slice/mariadb.service
└─3905 /usr/sbin/mariadbd
Oct 6 04:19:50 centos8 mariadbd[3905]: 2021-09-25 4:19:50 0 [Note] InnoDB: 10.5.12 started; log sequence number 45094; transaction id 20
Oct 6 04:19:50 centos8 mariadbd[3905]: 2021-09-25 4:19:50 0 [Note] Plugin 'FEEDBACK' is disabled.
Oct 6 04:19:50 centos8 mariadbd[3905]: 2021-09-25 4:19:50 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
Oct 6 04:19:50 centos8 mariadbd[3905]: 2021-09-25 4:19:50 0 [Note] InnoDB: Buffer pool(s) load completed at 210925 4:19:50
Oct 6 04:19:50 centos8 mariadbd[3905]: 2021-09-25 4:19:50 0 [Note] Server socket created on IP: '::'.
Oct 6 04:19:50 centos8 mariadbd[3905]: 2021-09-25 4:19:50 0 [Note] Reading of all Master_info entries succeeded
Oct 6 04:19:50 centos8 mariadbd[3905]: 2021-09-25 4:19:50 0 [Note] Added new Master_info '' to hash table
Oct 6 04:19:50 centos8 mariadbd[3905]: 2021-09-25 4:19:50 0 [Note] /usr/sbin/mariadbd: ready for connections.
Oct 6 04:19:50 centos8 mariadbd[3905]: Version: '10.5.12-MariaDB' socket: 'https://net.cloudinfrastructureservices.co.uk/var/lib/mysql/mysql.sock' port: 3306 MariaDB Server
Oct 6 04:19:50 centos8 systemd[1]: Started MariaDB 10.5.12 database server.
Now, verify the installed version of MariaDB using the following command:
mysqladmin version
You should see the MariaDB version in the following output:
mysqladmin Ver 9.1 Distrib 10.5.12-MariaDB, for Linux on x86_64
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Server version 10.5.12-MariaDB
Protocol version 10
Connection Localhost via UNIX socket
UNIX socket /var/lib/mysql/mysql.sock
Uptime: 39 sec
Threads: 1 Questions: 1 Slow queries: 0 Opens: 17 Open tables: 10 Queries per second avg: 0.025
By default, MariaDB installation is not secured on Cent OS. So it is recommended to secure the MariaDB installation and set the MariaDB root password. You can do it by running the mysql_secure_installation script:
mysql_secure_installation
You will be asked to provide your root password:
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:
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] n
Type n and hit Enter. You will be asked to set a root password:
... skipping.
You already have your root account protected, so you can safely answer 'n'.
Change the root password? [Y/n] Y
Press Y and hit Enter. You will be asked to set your root password:
New password:
Re-enter new password:
Provide your root password and hit Enter. You will be asked to remove the anonymous users:
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
Press Y and hit Enter. You will be asked to disallow root login remotely:
... 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 test database:
... 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
Press Y and hit Enter. You will be asked to reload the privilege table:
- 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 to finish the installation.
... 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!
First, you will need to log in to the MariaDB shell.
mysql -u root -p
Provide your MariaDB root password and hit Enter to log in.
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 12
Server version: 10.5.12-MariaDB MariaDB Server
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)]>
You should see all the users in the following output:
+-------------+
| User |
+-------------+
| mariadb.sys |
| mysql |
| root |
| testuser |
+-------------+
To grant all the privileges on testdb database to testuser, run:
MariaDB [(none)]> GRANT ALL PRIVILEGES ON testdb.* TO 'testuser'@localhost IDENTIFIED BY 'password';
Now, flush the privileges to apply the changes:
MariaDB [(none)]> FLUSH PRIVILEGES;
You can see all granted privileges using the following command:
MariaDB [(none)]> SHOW GRANTS FOR 'testuser'@localhost;
You should see the following output:
+-----------------------------------------------------------------------------------------------------------------+
| Grants for testuser@localhost |
+-----------------------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO `testuser`@`localhost` IDENTIFIED BY PASSWORD '*2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19' |
| GRANT ALL PRIVILEGES ON `testdb`.* TO `testuser`@`localhost` |
+-----------------------------------------------------------------------------------------------------------------+
In the above guide, you learned how to install the MariaDB database server on CentOS 8. You also learned how to create a database, user and table in MariaDB. You can now start using the MariaDB as a database backend with your application.
I am a fan of open source technology and have more than 10 years of experience working with Linux and Open Source technologies. I am one of the Linux technical writers for Cloud Infrastructure Services.
51vote
Article Rating
Subscribe
Login and comment with
I allow to create an account
When you login first time using a Social Login button, we collect your account public profile information shared by Social Login provider, based on your privacy settings. We also get your email address to automatically create an account for you in our website. Once your account is created, you'll be logged-in to this account.
DisagreeAgree
Login and comment with
I allow to create an account
When you login first time using a Social Login button, we collect your account public profile information shared by Social Login provider, based on your privacy settings. We also get your email address to automatically create an account for you in our website. Once your account is created, you'll be logged-in to this account.