How to install MariaDB Database Server on CentOS 8

Update CentOS 8 Software Packages:

[root@alldba ~]# 
[root@alldba ~]# dnf update -y
CentOS Stream 8 - AppStream                                                                                                                                                                              2.0 MB/s |  25 MB     00:12    
CentOS Stream 8 - BaseOS                                                                                                                                                                                 1.1 MB/s |  25 MB     00:22    
CentOS Stream 8 - Extras                                                                                                                                                                                  13 kB/s |  18 kB     00:01    
CentOS Stream 8 - Extras common packages                                                                                                                                                                 3.7 kB/s | 5.2 kB     00:01    
Dependencies resolved.
Nothing to do.
Complete!
[root@alldba ~]# 

Install MariaDB Yum Repository in CentOS 8:

Create a yum repository file as follows.

 

[root@alldba ~]# vi /etc/yum.repos.d/MariaDB.repo

Add following directives in this file.

# MariaDB 10.5 CentOS repository list - created 2020-05-29 08:37 UTC
# http://downloads.mariadb.org/mariadb/repositories/
[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

Build cache for MariaDB yum repository.

[root@alldba ~]# dnf makecache
CentOS Stream 8 - AppStream                                                                                                                                                                              4.6 kB/s | 4.4 kB     00:00    
CentOS Stream 8 - BaseOS                                                                                                                                                                                 4.0 kB/s | 3.9 kB     00:00    
CentOS Stream 8 - Extras                                                                                                                                                                                 1.6 kB/s | 2.9 kB     00:01    
CentOS Stream 8 - Extras common packages                                                                                                                                                                 2.5 kB/s | 3.0 kB     00:01    
MariaDB                                                                                                                                                                                                  145 kB/s | 606 kB     00:04    
Metadata cache created.
[root@alldba ~]# 

Install MariaDB Server 10.5 on CentOS 8:

We have added the MariaDB yum repository, now we can easily install MariaDB Server using dnf command.

[root@alldba ~]# 
[root@alldba ~]# dnf install -y MariaDB-server
Last metadata expiration check: 0:01:17 ago on Wed 02 Nov 2022 05:25:02 PM CST.
Dependencies resolved.
=========================================================================================================================================================================================================================================
 Package                                                     Architecture                                        Version                                                    Repository                                              Size
=========================================================================================================================================================================================================================================
Installing:
 MariaDB-server                                              x86_64                                              10.5.17-1.el8                                              mariadb                                                 26 M
Installing dependencies:
 MariaDB-client                                              x86_64                                              10.5.17-1.el8                                              mariadb                                                 13 M
 MariaDB-common                                              x86_64                                              10.5.17-1.el8                                              mariadb                                                 88 k
 MariaDB-shared                                              x86_64                                              10.5.17-1.el8                                              mariadb                                                115 k
 galera-4                                                    x86_64                                              26.4.12-1.el8                                              mariadb                                                 13 M
 socat                                                       x86_64                                              1.7.4.1-1.el8                                              appstream                                              323 k

Transaction Summary
=========================================================================================================================================================================================================================================
Install  6 Packages

Total download size: 54 M
Installed size: 258 M
Downloading Packages:
(1/6): socat-1.7.4.1-1.el8.x86_64.rpm                                                                                                                                                                    515 kB/s | 323 kB     00:00    
(2/6): MariaDB-common-10.5.17-1.el8.x86_64.rpm                                                                                                                                                            44 kB/s |  88 kB     00:02    
(3/6): MariaDB-shared-10.5.17-1.el8.x86_64.rpm                                                                                                                                                            36 kB/s | 115 kB     00:03    
(4/6): MariaDB-server-10.5.17-1.el8.x86_64.rpm                                                                                                                                                           2.2 MB/s |  26 MB     00:12    
(5/6): galera-4-26.4.12-1.el8.x86_64.rpm                                                                                                                                                                 1.3 MB/s |  13 MB     00:10    
(6/6): MariaDB-client-10.5.17-1.el8.x86_64.rpm                                                                                                                                                            73 kB/s |  13 MB     03:08    
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                                                                                    291 kB/s |  54 MB     03:09     
CentOS Stream 8 - AppStream                                                                                                                                                                              116 kB/s | 1.6 kB     00:00    
Importing GPG key 0x8483C65D:
 Userid     : "CentOS (CentOS Official Signing Key) <security@centos.org>"
 Fingerprint: 99DB 70FA E1D7 CE22 7FB6 4882 05B5 55B3 8483 C65D
 From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
Key imported successfully
MariaDB                                                                                                                                                                                                  3.5 kB/s | 8.2 kB     00:02    
Importing GPG key 0x1BB943DB:
 Userid     : "MariaDB Package Signing Key <package-signing-key@mariadb.org>"
 Fingerprint: 1993 69E5 404B D5FC 7D2F E43B CBCB 082A 1BB9 43DB
 From       : https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
Key imported successfully
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                                                                                                                                 1/1 
  Running scriptlet: MariaDB-shared-10.5.17-1.el8.x86_64                                                                                                                                                                             1/6 
  Installing       : MariaDB-shared-10.5.17-1.el8.x86_64                                                                                                                                                                             1/6 
  Running scriptlet: MariaDB-shared-10.5.17-1.el8.x86_64                                                                                                                                                                             1/6 
  Running scriptlet: MariaDB-common-10.5.17-1.el8.x86_64                                                                                                                                                                             2/6 
  Installing       : MariaDB-common-10.5.17-1.el8.x86_64                                                                                                                                                                             2/6 
  Running scriptlet: MariaDB-common-10.5.17-1.el8.x86_64                                                                                                                                                                             2/6 
  Running scriptlet: MariaDB-client-10.5.17-1.el8.x86_64                                                                                                                                                                             3/6 
  Installing       : MariaDB-client-10.5.17-1.el8.x86_64                                                                                                                                                                             3/6 
  Running scriptlet: MariaDB-client-10.5.17-1.el8.x86_64                                                                                                                                                                             3/6 
  Installing       : socat-1.7.4.1-1.el8.x86_64                                                                                                                                                                                      4/6 
  Running scriptlet: galera-4-26.4.12-1.el8.x86_64                                                                                                                                                                                   5/6 
  Installing       : galera-4-26.4.12-1.el8.x86_64                                                                                                                                                                                   5/6 
  Running scriptlet: galera-4-26.4.12-1.el8.x86_64                                                                                                                                                                                   5/6 
  Running scriptlet: MariaDB-server-10.5.17-1.el8.x86_64                                                                                                                                                                             6/6 
  Installing       : MariaDB-server-10.5.17-1.el8.x86_64                                                                                                                                                                             6/6 
  Running scriptlet: MariaDB-server-10.5.17-1.el8.x86_64                                                                                                                                                                             6/6 


Two all-privilege accounts were created.
One is root@localhost, it has no password, but you need to
be system 'root' user to connect. Use, for example, sudo mysql
The second is mysql@localhost, 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

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

The latest information about MariaDB is available at https://mariadb.org/.

Consider joining MariaDB's strong and vibrant community:
https://mariadb.org/get-involved/


  Verifying        : socat-1.7.4.1-1.el8.x86_64                                                                                                                                                                                      1/6 
  Verifying        : MariaDB-client-10.5.17-1.el8.x86_64                                                                                                                                                                             2/6 
  Verifying        : MariaDB-common-10.5.17-1.el8.x86_64                                                                                                                                                                             3/6 
  Verifying        : MariaDB-server-10.5.17-1.el8.x86_64                                                                                                                                                                             4/6 
  Verifying        : MariaDB-shared-10.5.17-1.el8.x86_64                                                                                                                                                                             5/6 
  Verifying        : galera-4-26.4.12-1.el8.x86_64                                                                                                                                                                                   6/6 

Installed:
  MariaDB-client-10.5.17-1.el8.x86_64      MariaDB-common-10.5.17-1.el8.x86_64      MariaDB-server-10.5.17-1.el8.x86_64      MariaDB-shared-10.5.17-1.el8.x86_64      galera-4-26.4.12-1.el8.x86_64      socat-1.7.4.1-1.el8.x86_64     

Complete!
[root@alldba ~]# 

Enable and start MariaDB service.

[root@alldba ~]# systemctl enable --now mariadb.service
Created symlink /etc/systemd/system/multi-user.target.wants/mariadb.service → /usr/lib/systemd/system/mariadb.service.
[root@alldba ~]#

Verify the status for MariaDB service.

[root@alldba ~]# systemctl status mariadb.service
● mariadb.service - MariaDB 10.5.17 database server
   Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled)
  Drop-In: /etc/systemd/system/mariadb.service.d
           └─migrated-from-my.cnf-settings.conf
   Active: active (running) since Wed 2022-11-02 17:32:10 CST; 30s ago
     Docs: man:mariadbd(8)
           https://mariadb.com/kb/en/library/systemd/
  Process: 33426 ExecStartPost=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
  Process: 33395 ExecStartPre=/bin/sh -c [ ! -e /usr/bin/galera_recovery ] && VAR= ||   VAR=`cd /usr/bin/..; /usr/bin/galera_recovery`; [ $? -eq 0 ]   && systemctl set-environment _WSREP_START_POSITION=$VAR || exit 1 (code=exited, s>
  Process: 33393 ExecStartPre=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
 Main PID: 33405 (mariadbd)
   Status: "Taking your SQL requests now..."
    Tasks: 20 (limit: 18222)
   Memory: 69.4M
   CGroup: /system.slice/mariadb.service
           └─33405 /usr/sbin/mariadbd

Nov 02 17:32:10 alldba mariadbd[33405]: 2022-11-02 17:32:10 0 [Note] InnoDB: 10.5.17 started; log sequence number 45106; transaction id 20
Nov 02 17:32:10 alldba mariadbd[33405]: 2022-11-02 17:32:10 0 [Note] Plugin 'FEEDBACK' is disabled.
Nov 02 17:32:10 alldba mariadbd[33405]: 2022-11-02 17:32:10 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
Nov 02 17:32:10 alldba mariadbd[33405]: 2022-11-02 17:32:10 0 [Note] InnoDB: Buffer pool(s) load completed at 221102 17:32:10
Nov 02 17:32:10 alldba mariadbd[33405]: 2022-11-02 17:32:10 0 [Note] Server socket created on IP: '::'.
Nov 02 17:32:10 alldba mariadbd[33405]: 2022-11-02 17:32:10 0 [Note] Reading of all Master_info entries succeeded
Nov 02 17:32:10 alldba mariadbd[33405]: 2022-11-02 17:32:10 0 [Note] Added new Master_info '' to hash table
Nov 02 17:32:10 alldba mariadbd[33405]: 2022-11-02 17:32:10 0 [Note] /usr/sbin/mariadbd: ready for connections.
Nov 02 17:32:10 alldba mariadbd[33405]: Version: '10.5.17-MariaDB'  socket: '/var/lib/mysql/mysql.sock'  port: 3306  MariaDB Server
Nov 02 17:32:10 alldba systemd[1]: Started MariaDB 10.5.17 database server.
lines 1-27/27 (END)

As mentioned in the installation output,

  • Linux root user can connect to MariaDB server as MariaDB root user without any password
  • Linux mysql user can connect to MariaDB server as MariaDB mysql user without any password

Also no other Linux user is allowed to login as MariaDB root or mysql users.

To allow the other Linux users to login as root or mysql user we need to set the password for these database users.

Connect with MariaDB server by using new mariadb command.

[root@alldba ~]# 
[root@alldba ~]# mariadb -u root
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 10.5.17-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)]> 

Set strong passwords for root and mysql users.

MariaDB [(none)]> 
MariaDB [(none)]> alter user 'root'@'localhost' identified by 'Maxwell@123456';
Query OK, 0 rows affected (0.001 sec)

MariaDB [(none)]> 
MariaDB [(none)]> 
MariaDB [(none)]> alter user 'mysql'@'localhost' identified by 'Maxwell@123456';
Query OK, 0 rows affected (0.001 sec)

MariaDB [(none)]> 

Reload the privileges tables.

MariaDB [(none)]> 
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.001 sec)

MariaDB [(none)]>

List available databases in MariaDB server.

MariaDB [(none)]> 
MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
+--------------------+
4 rows in set (0.001 sec)

MariaDB [(none)]> 

Exit from MariaDB Shell.

MariaDB [(none)]> 
MariaDB [(none)]> exit
Bye
[root@alldba ~]# 

Our MariaDB Server 10.5 has been installed successfully.

Configure Database Security for MariaDB Server:

We can optionally remove the test databases and restrict the remote logins by root user.

For this purpose, we can use new mariadb-secure-installation command.

[root@alldba ~]# 
[root@alldba ~]# mariadb-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): 
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
Enter current password for root (enter for none): 
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
Enter current password for root (enter for none): 
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
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] n
 ... skipping.

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

Change the root password? [Y/n] n
 ... skipping.

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!
[root@alldba ~]# 

We have successfully installed and configured MariaDB Server 10.5 on CentOS 8.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值