在Rocky、Almalinux、CentOS、openEuler、AnolisOS、OpenCloudOS、Kylin Server、UOS Server上安装MariaDB:
[root@rocky10 ~]# yum list mariadb-server --showduplicates
Last metadata expiration check: 0:08:25 ago on Fri 08 Aug 2025 01:13:14 PM CST.
Available Packages
mariadb-server.x86_64 3:10.11.11-1.el10 appstream
[root@rocky10 ~]# yum -y install mariadb-server
[root@rocky10 ~]# systemctl enable --now mariadb
[root@rocky10 ~]# ls /var/lib/mysql
aria_log.00000001 ddl_recovery.log ibdata1 ibtmp1 mysql mysql_upgrade_info sys
aria_log_control ib_buffer_pool ib_logfile0 multi-master.info mysql.sock performance_schema
[root@rocky10 ~]# mariadb -V
mariadb Ver 15.1 Distrib 10.11.11-MariaDB, for Linux (x86_64) using EditLine wrapper
[root@rocky10 ~]# systemctl status mariadb
● mariadb.service - MariaDB 10.11 database server
Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; preset: disabled)
Active: active (running) since Fri 2025-08-08 13:28:01 CST; 1min 11s ago
Invocation: 3d54eb415ece4dcebce26a9b4e05034e
Docs: man:mariadbd(8)
https://mariadb.com/kb/en/library/systemd/
Process: 1619 ExecStartPre=/usr/libexec/mariadb-check-socket (code=exited, status=0/SUCCESS)
Process: 1642 ExecStartPre=/usr/libexec/mariadb-prepare-db-dir mariadb.service (code=exited, status=0/SUCCES>
Process: 1750 ExecStartPost=/usr/libexec/mariadb-check-upgrade (code=exited, status=0/SUCCESS)
Main PID: 1737 (mariadbd)
Status: "Taking your SQL requests now..."
Tasks: 8 (limit: 10481)
Memory: 206.2M (peak: 231.3M)
CPU: 889ms
CGroup: /system.slice/mariadb.service
└─1737 /usr/libexec/mariadbd --basedir=/usr
Aug 08 13:28:01 rocky10 mariadb-prepare-db-dir[1681]: you need to be the system 'mysql' user to connect.
Aug 08 13:28:01 rocky10 mariadb-prepare-db-dir[1681]: After connecting you can set the password, if you would ne>
Aug 08 13:28:01 rocky10 mariadb-prepare-db-dir[1681]: able to connect as any of these users with a password and >
Aug 08 13:28:01 rocky10 mariadb-prepare-db-dir[1681]: See the MariaDB Knowledgebase at https://mariadb.com/kb
Aug 08 13:28:01 rocky10 mariadb-prepare-db-dir[1681]: Please report any problems at https://mariadb.org/jira
Aug 08 13:28:01 rocky10 mariadb-prepare-db-dir[1681]: The latest information about MariaDB is available at https>
Aug 08 13:28:01 rocky10 mariadb-prepare-db-dir[1681]: Consider joining MariaDB's strong and vibrant community:
Aug 08 13:28:01 rocky10 mariadb-prepare-db-dir[1681]: https://mariadb.org/get-involved/
Aug 08 13:28:01 rocky10 (mariadbd)[1737]: mariadb.service: Referenced but unset environment variable evaluates t>
Aug 08 13:28:01 rocky10 systemd[1]: Started mariadb.service - MariaDB 10.11 database server.
[root@rocky10 ~]# mariadb
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 10.11.11-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)]> status
--------------
mysql Ver 15.1 Distrib 10.11.11-MariaDB, for Linux (x86_64) using EditLine wrapper
Connection id: 3
Current database:
Current user: root@localhost
SSL: Not in use
Current pager: stdout
Using outfile: ''
Using delimiter: ;
Server: MariaDB
Server version: 10.11.11-MariaDB MariaDB Server
Protocol version: 10
Connection: Localhost via UNIX socket
Server characterset: latin1
Db characterset: latin1
Client characterset: utf8mb3
Conn. characterset: utf8mb3
UNIX socket: /var/lib/mysql/mysql.sock
Uptime: 1 min 44 sec
Threads: 1 Questions: 4 Slow queries: 0 Opens: 17 Open tables: 10 Queries per second avg: 0.038
--------------
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.001 sec)
MariaDB [(none)]> exit
Bye
在Ubuntu和Debian上安装MariaDB:
root@ubuntu2404:~# apt-cache madison mariadb-server
mariadb-server | 1:10.11.13-0ubuntu0.24.04.1 | https://mirrors.aliyun.com/ubuntu noble-updates/universe amd64 Packages
mariadb-server | 1:10.11.13-0ubuntu0.24.04.1 | https://mirrors.aliyun.com/ubuntu noble-security/universe amd64 Packages
mariadb-server | 1:10.11.7-2ubuntu2 | https://mirrors.aliyun.com/ubuntu noble/universe amd64 Packages
root@ubuntu2404:~# apt -y install mariadb-server
root@ubuntu2404:~# systemctl enable --now mariadb
root@ubuntu2404:~# ls /var/lib/mysql
aria_log.00000001 ddl_recovery.log ib_buffer_pool ib_logfile0 multi-master.info mysql_upgrade_info sys
aria_log_control debian-10.11.flag ibdata1 ibtmp1 mysql performance_schema
root@ubuntu2404:~# mariadb -V
mysql Ver 15.1 Distrib 10.11.13-MariaDB, for debian-linux-gnu (x86_64) using EditLine wrapper
root@ubuntu2404:~# systemctl status mariadb
● mariadb.service - MariaDB 10.11.13 database server
Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; preset: enabled)
Active: active (running) since Fri 2025-08-08 15:43:17 CST; 3min 43s ago
Docs: man:mariadbd(8)
https://mariadb.com/kb/en/library/systemd/
Main PID: 1949 (mariadbd)
Status: "Taking your SQL requests now..."
Tasks: 10 (limit: 14588)
Memory: 78.9M (peak: 82.0M)
CPU: 554ms
CGroup: /system.slice/mariadb.service
└─1949 /usr/sbin/mariadbd
Aug 08 15:43:17 ubuntu2404 mariadbd[1949]: 2025-08-08 15:43:17 0 [Note] InnoDB: log sequence number 45502; trans>
Aug 08 15:43:17 ubuntu2404 mariadbd[1949]: 2025-08-08 15:43:17 0 [Note] Plugin 'FEEDBACK' is disabled.
Aug 08 15:43:17 ubuntu2404 mariadbd[1949]: 2025-08-08 15:43:17 0 [Note] InnoDB: Loading buffer pool(s) from /var>
Aug 08 15:43:17 ubuntu2404 mariadbd[1949]: 2025-08-08 15:43:17 0 [Warning] You need to use --log-bin to make --e>
Aug 08 15:43:17 ubuntu2404 mariadbd[1949]: 2025-08-08 15:43:17 0 [Note] Server socket created on IP: '127.0.0.1'.
Aug 08 15:43:17 ubuntu2404 mariadbd[1949]: 2025-08-08 15:43:17 0 [Note] InnoDB: Buffer pool(s) load completed at>
Aug 08 15:43:17 ubuntu2404 mariadbd[1949]: 2025-08-08 15:43:17 0 [Note] /usr/sbin/mariadbd: ready for connection>
Aug 08 15:43:17 ubuntu2404 mariadbd[1949]: Version: '10.11.13-MariaDB-0ubuntu0.24.04.1' socket: '/run/mysqld/my>
Aug 08 15:43:17 ubuntu2404 systemd[1]: Started mariadb.service - MariaDB 10.11.13 database server.
Aug 08 15:43:17 ubuntu2404 /etc/mysql/debian-start[1967]: Upgrading MariaDB tables if necessary.
root@ubuntu2404:~# mariadb
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 31
Server version: 10.11.13-MariaDB-0ubuntu0.24.04.1 Ubuntu 24.04
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)]> status
--------------
mysql Ver 15.1 Distrib 10.11.13-MariaDB, for debian-linux-gnu (x86_64) using EditLine wrapper
Connection id: 31
Current database:
Current user: root@localhost
SSL: Not in use
Current pager: stdout
Using outfile: ''
Using delimiter: ;
Server: MariaDB
Server version: 10.11.13-MariaDB-0ubuntu0.24.04.1 Ubuntu 24.04
Protocol version: 10
Connection: Localhost via UNIX socket
Server characterset: utf8mb4
Db characterset: utf8mb4
Client characterset: utf8mb3
Conn. characterset: utf8mb3
UNIX socket: /run/mysqld/mysqld.sock
Uptime: 4 min 13 sec
Threads: 1 Questions: 61 Slow queries: 0 Opens: 33 Open tables: 26 Queries per second avg: 0.241
--------------
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.000 sec)
MariaDB [(none)]> exit
Bye
在openSUSE上安装MariaDB:
opensuse15:~ # zypper search "mariadb"
Loading repository data...
Reading installed packages...
S | Name | Summary | Type
--+--------------------------+---------------------------------------------------------------------+-----------
| libmariadb-devel | Development files for the MariaDB Connector C API | package
| libmariadb3 | MariaDB connector in C | package
| libmariadb3-32bit | MariaDB connector in C | package
| libmariadb_plugins | Plugins for the MariaDB C Connector | package
| libmariadbd-devel | MariaDB embedded server development files | package
| libmariadbd19 | MariaDB embedded server library | package
| libmariadbd104-devel | MariaDB embedded server development files | package
| libmariadbprivate | Additional internal libraries for the MariaDB C Connector | package
| mariadb | Server part of MariaDB | package
| mariadb | Server part of MariaDB | srcpackage
| mariadb-bench | Benchmarks for MariaDB | package
| mariadb-client | Client for MariaDB | package
| mariadb-connector-odbc | MariaDB ODBC Connector | package
| mariadb-errormessages | The error messages files required by server, client and libmariadbd | package
| mariadb-galera | The configuration files and scripts for galera replication | package
| mariadb-rpm-macros | MariaDB RPM macros | package
| mariadb-test | Testsuite for MariaDB | package
| mariadb-tools | MariaDB tools | package
| mariadb104 | Server part of MariaDB | srcpackage
| mariadb104 | Server part of MariaDB | package
| mariadb104-bench | Benchmarks for MariaDB | package
| mariadb104-client | Client for MariaDB | package
| mariadb104-errormessages | The error messages files required by server, client and libmariadbd | package
| mariadb104-galera | The configuration files and scripts for galera replication | package
| mariadb104-rpm-macros | MariaDB RPM macros | package
| mariadb104-test | Testsuite for MariaDB | package
| mariadb104-tools | MariaDB tools | package
opensuse15:~ # zypper info mariadb
Loading repository data...
Reading installed packages...
Information for package mariadb:
--------------------------------
Repository : Update repository with updates from SUSE Linux Enterprise 15
Name : mariadb
Version : 10.11.11-150600.4.10.1
Arch : x86_64
Vendor : SUSE LLC <https://www.suse.com/>
Installed Size : 158.8 MiB
Installed : No
Status : not installed
Source package : mariadb-10.11.11-150600.4.10.1.src
Upstream URL : https://www.mariadb.org
Summary : Server part of MariaDB
Description :
MariaDB is an open-source, multi-threaded, relational database management
system. It's a backward compatible, drop-in replacement branch of the
MySQL Community Server.
This package only contains the server-side programs.
opensuse15:~ # zypper install -y mariadb
opensuse15:~ # systemctl enable --now mariadb
opensuse15:~ # ls /var/lib/mysql
aria_log.00000001 ib_buffer_pool ibtmp1 mysql_upgrade_info sys
aria_log_control ib_logfile0 multi-master.info opensuse15.pid test
ddl_recovery.log ibdata1 mysql performance_schema
opensuse15:~ # mariadb -V
mariadb Ver 15.1 Distrib 10.11.11-MariaDB, for Linux (x86_64) using EditLine wrapper
opensuse15:~ # systemctl status mariadb
● mariadb.service - MariaDB database server
Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; preset: disabled)
Active: active (running) since Sun 2025-08-17 14:25:20 CST; 43s ago
Docs: man:mysqld(8)
https://mariadb.com/kb/en/library/systemd/
Process: 13918 ExecStartPre=/usr/lib/mysql/mysql-systemd-helper install (code=exited, status=0/SUCCESS)
Process: 13968 ExecStartPre=/usr/lib/mysql/mysql-systemd-helper upgrade (code=exited, status=0/SUCCESS)
Main PID: 13975 (mysqld)
Status: "Taking your SQL requests now..."
Tasks: 10 (limit: 2250)
CPU: 1.067s
CGroup: /system.slice/mariadb.service
└─13975 /usr/sbin/mysqld --defaults-file=/etc/my.cnf --user=mysql --socket=/run/mysql/mysql.sock
Aug 17 14:25:19 opensuse15 mysql-systemd-helper[13924]: The second is mysql@localhost, it has no password either>
Aug 17 14:25:19 opensuse15 mysql-systemd-helper[13924]: you need to be the system 'mysql' user to connect.
Aug 17 14:25:19 opensuse15 mysql-systemd-helper[13924]: After connecting you can set the password, if you would >
Aug 17 14:25:19 opensuse15 mysql-systemd-helper[13924]: able to connect as any of these users with a password an>
Aug 17 14:25:19 opensuse15 mysql-systemd-helper[13924]: See the MariaDB Knowledgebase at https://mariadb.com/kb
Aug 17 14:25:19 opensuse15 mysql-systemd-helper[13924]: Please report any problems at https://mariadb.org/jira
Aug 17 14:25:19 opensuse15 mysql-systemd-helper[13924]: The latest information about MariaDB is available at htt>
Aug 17 14:25:19 opensuse15 mysql-systemd-helper[13924]: Consider joining MariaDB's strong and vibrant community:
Aug 17 14:25:19 opensuse15 mysql-systemd-helper[13924]: https://mariadb.org/get-involved/
Aug 17 14:25:20 opensuse15 systemd[1]: Started MariaDB database server.
opensuse15:~ # mariadb
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 10.11.11-MariaDB MariaDB package
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)]> status
--------------
mariadb Ver 15.1 Distrib 10.11.11-MariaDB, for Linux (x86_64) using EditLine wrapper
Connection id: 3
Current database:
Current user: root@localhost
SSL: Not in use
Current pager: less
Using outfile: ''
Using delimiter: ;
Server: MariaDB
Server version: 10.11.11-MariaDB MariaDB package
Protocol version: 10
Connection: Localhost via UNIX socket
Server characterset: utf8mb4
Db characterset: utf8mb4
Client characterset: utf8mb3
Conn. characterset: utf8mb3
UNIX socket: /run/mysql/mysql.sock
Uptime: 1 min 7 sec
Threads: 1 Questions: 4 Slow queries: 0 Opens: 17 Open tables: 10 Queries per second avg: 0.059
--------------
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
| test | # 有test数据库
+--------------------+
5 rows in set (0.000 sec)
MariaDB [(none)]> select user,host from mysql.user;
+-------------+------------+
| User | Host |
+-------------+------------+
| PUBLIC | |
| | localhost | # 有匿名用户
| mariadb.sys | localhost |
| mysql | localhost |
| root | localhost |
| | opensuse15 | # 有远程登录用户
+-------------+------------+
6 rows in set (0.001 sec)
MariaDB [(none)]> exit
Bye
# 有test数据库、匿名用户和远程登录用户,需要安全初始化
opensuse15:~ # 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): # 输入 root 的当前密码(不输入),直接敲回车
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 # 输入y,切换到 unix_socket 身份验证
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] n # 输入n,不设置root密码
... 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 # 输入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 # 输入y,禁止 root 远程登录
... 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 # 输入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 # 输入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!
opensuse15:~ # mariadb
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 14
Server version: 10.11.11-MariaDB MariaDB package
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)]> status
--------------
mariadb Ver 15.1 Distrib 10.11.11-MariaDB, for Linux (x86_64) using EditLine wrapper
Connection id: 14
Current database:
Current user: root@localhost
SSL: Not in use
Current pager: less
Using outfile: ''
Using delimiter: ;
Server: MariaDB
Server version: 10.11.11-MariaDB MariaDB package
Protocol version: 10
Connection: Localhost via UNIX socket
Server characterset: utf8mb4
Db characterset: utf8mb4
Client characterset: utf8mb3
Conn. characterset: utf8mb3
UNIX socket: /run/mysql/mysql.sock
Uptime: 2 min 34 sec
Threads: 1 Questions: 30 Slow queries: 0 Opens: 21 Open tables: 14 Queries per second avg: 0.194
--------------
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.000 sec)
# 没有test数据库
MariaDB [(none)]> select user,host from mysql.user;
+-------------+-----------+
| User | Host |
+-------------+-----------+
| PUBLIC | |
| mariadb.sys | localhost |
| mysql | localhost |
| root | localhost |
+-------------+-----------+
4 rows in set (0.001 sec)
# 没有匿名用户和远程登录用户
MariaDB [(none)]> exit
Bye
添加官方资源库,去“https://mariadb.org”网站下载,选择“Download”。
图2 MariaDB首页
在打开的网页,在“MariaDB Server Repositories”下面选择“Choose a distribution为:Red Hat Enterprise Linux 9”,选择“Choose a MariaDB Server version为:11.8”,选择“Mirror为:清华大学 TUNA 协会 (Tsinghua University TUNA Association)”,然后根据下面提示操作。
图3 MariaDB添加资源库
[root@rocky9 ~]# cat > /etc/yum.repos.d/MariaDB.repo <<EOF
# MariaDB 11.8 RedHatEnterpriseLinux repository list - created 2025-08-17 02:34 UTC
# https://mariadb.org/download/
[mariadb]
name = MariaDB
# rpm.mariadb.org is a dynamic mirror if your preferred mirror goes offline. See https://mariadb.org/mirrorbits/ for details.
# baseurl = https://rpm.mariadb.org/11.8/rhel/$releasever/$basearch
baseurl = https://mirrors.tuna.tsinghua.edu.cn/mariadb/yum/11.8/rhel/\$releasever/\$basearch
# gpgkey = https://rpm.mariadb.org/RPM-GPG-KEY-MariaDB
gpgkey = https://mirrors.tuna.tsinghua.edu.cn/mariadb/yum/RPM-GPG-KEY-MariaDB
gpgcheck = 1
EOF
[root@rocky9 ~]# dnf install -y MariaDB-server
[root@rocky9 ~]# systemctl enable --now mariadb
[root@rocky9 ~]# ls /var/lib/mysql/
aria_log.00000001 ib_buffer_pool ibtmp1 mysql rocky9.pid test undo003
aria_log_control ibdata1 mariadb_upgrade_info mysql.sock sys undo001
ddl_recovery.log ib_logfile0 multi-master.info performance_schema tc.log undo002
[root@rocky9 ~]# mariadb -V
mariadb from 11.8.3-MariaDB, client 15.2 for Linux (x86_64) using EditLine wrapper
[root@rocky9 ~]# systemctl status mariadb
● mariadb.service - MariaDB 11.8.3 database server
Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; preset: disabled)
Drop-In: /etc/systemd/system/mariadb.service.d
└─migrated-from-my.cnf-settings.conf
Active: active (running) since Sun 2025-08-17 10:36:26 CST; 1min 17s ago
Docs: man:mariadbd(8)
https://mariadb.com/kb/en/library/systemd/
Process: 12291 ExecStartPre=/bin/sh -c [ ! -e /usr/bin/galera_recovery ] && VAR= || VAR=`/usr/bin/galera_r>
Process: 12308 ExecStartPost=/bin/rm -f /var/lib/mysql/wsrep-start-position (code=exited, status=0/SUCCESS)
Main PID: 12298 (mariadbd)
Status: "Taking your SQL requests now..."
Tasks: 8 (limit: 13443)
Memory: 126.7M
CPU: 563ms
CGroup: /system.slice/mariadb.service
└─12298 /usr/sbin/mariadbd
Aug 17 10:36:25 rocky9 mariadbd[12298]: 2025-08-17 10:36:25 0 [Note] InnoDB: Loading buffer pool(s) from /var/li>
Aug 17 10:36:25 rocky9 mariadbd[12298]: 2025-08-17 10:36:25 0 [Note] Plugin 'FEEDBACK' is disabled.
Aug 17 10:36:25 rocky9 mariadbd[12298]: 2025-08-17 10:36:25 0 [Note] Plugin 'wsrep-provider' is disabled.
Aug 17 10:36:25 rocky9 mariadbd[12298]: 2025-08-17 10:36:25 0 [Note] InnoDB: Buffer pool(s) load completed at 25>
Aug 17 10:36:26 rocky9 mariadbd[12298]: 2025-08-17 10:36:26 0 [Note] Server socket created on IP: '0.0.0.0', por>
Aug 17 10:36:26 rocky9 mariadbd[12298]: 2025-08-17 10:36:26 0 [Note] Server socket created on IP: '::', port: '3>
Aug 17 10:36:26 rocky9 mariadbd[12298]: 2025-08-17 10:36:26 0 [Note] mariadbd: Event Scheduler: Loaded 0 events
Aug 17 10:36:26 rocky9 mariadbd[12298]: 2025-08-17 10:36:26 0 [Note] /usr/sbin/mariadbd: ready for connections.
Aug 17 10:36:26 rocky9 mariadbd[12298]: Version: '11.8.3-MariaDB' socket: '/var/lib/mysql/mysql.sock' port: 33>
Aug 17 10:36:26 rocky9 systemd[1]: Started MariaDB 11.8.3 database server.
[root@rocky9 ~]# mariadb
mysql: Deprecated program name. It will be removed in a future release, use '/usr/bin/mariadb' instead
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 11.8.3-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)]> status
--------------
mysql from 11.8.3-MariaDB, client 15.2 for Linux (x86_64) using EditLine wrapper
Connection id: 3
Current database:
Current user: root@localhost
SSL: Cipher in use is TLS_AES_256_GCM_SHA384, cert is OK
Current pager: stdout
Using outfile: ''
Using delimiter: ;
Server: MariaDB
Server version: 11.8.3-MariaDB MariaDB Server
Protocol version: 10
Connection: Localhost via UNIX socket
Server characterset: utf8mb4
Db characterset: utf8mb4
Client characterset: utf8mb4
Conn. characterset: utf8mb4
UNIX socket: /var/lib/mysql/mysql.sock
Uptime: 1 min 45 sec
Threads: 1 Questions: 4 Slow queries: 0 Opens: 17 Open tables: 10 Queries per second avg: 0.038
--------------
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
| test | # 有test数据库
+--------------------+
5 rows in set (0.001 sec)
MariaDB [(none)]> select user,host from mysql.user;
+-------------+-----------+
| User | Host |
+-------------+-----------+
| PUBLIC | |
| | localhost | # 有匿名用户
| mariadb.sys | localhost |
| mysql | localhost |
| root | localhost |
| | rocky9 | # 有远程登录用户
+-------------+-----------+
6 rows in set (0.001 sec)
MariaDB [(none)]> exit
Bye
# 有test数据库、匿名用户和远程登录用户,需要安全初始化
[root@rocky9 ~]# 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): # 输入 root 的当前密码(不输入),直接敲回车
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 # 输入y,切换到 unix_socket 身份验证
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] n # 输入n,不设置root密码
... 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 # 输入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 # 输入y,禁止 root 远程登录
... 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 # 输入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 # 输入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@rocky9 ~]# mariadb
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 14
Server version: 11.8.3-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)]> status
--------------
mariadb from 11.8.3-MariaDB, client 15.2 for Linux (x86_64) using EditLine wrapper
Connection id: 14
Current database:
Current user: root@localhost
SSL: Cipher in use is TLS_AES_256_GCM_SHA384, cert is OK
Current pager: stdout
Using outfile: ''
Using delimiter: ;
Server: MariaDB
Server version: 11.8.3-MariaDB MariaDB Server
Protocol version: 10
Connection: Localhost via UNIX socket
Server characterset: utf8mb4
Db characterset: utf8mb4
Client characterset: utf8mb4
Conn. characterset: utf8mb4
UNIX socket: /var/lib/mysql/mysql.sock
Uptime: 7 min 59 sec
Threads: 1 Questions: 30 Slow queries: 0 Opens: 18 Open tables: 11 Queries per second avg: 0.062
--------------
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.001 sec)
# 没有test数据库
MariaDB [(none)]> select user,host from mysql.user;
+-------------+-----------+
| User | Host |
+-------------+-----------+
| PUBLIC | |
| mariadb.sys | localhost |
| mysql | localhost |
| root | localhost |
+-------------+-----------+
4 rows in set (0.001 sec)
# 没有匿名用户和远程登录用户
MariaDB [(none)]> exit
Bye
添加官方资源库,去“https://mariadb.org”网站下载,选择“Download”。
图4 MariaDB首页
在打开的网页,在“MariaDB Server Repositories”下面选择“Choose a distribution为:24.04 "noble"”,选择“Choose a MariaDB Server version为:11.8”,选择“Mirror为:清华大学 TUNA 协会 (Tsinghua University TUNA Association)”,然后根据下面提示操作。
图5 MariaDB添加资源库
apt install -y apt-transport-https curl
mkdir -p /etc/apt/keyrings
curl -o /etc/apt/keyrings/mariadb-keyring.pgp 'https://mariadb.org/mariadb_release_signing_key.pgp'
cat > /etc/apt/sources.list.d/mariadb.sources <<EOF
# MariaDB 11.8 repository list - created 2025-08-17 03:03 UTC
# https://mariadb.org/download/
X-Repolib-Name: MariaDB
Types: deb
# deb.mariadb.org is a dynamic mirror if your preferred mirror goes offline. See https://mariadb.org/mirrorbits/ for details.
# URIs: https://deb.mariadb.org/11.8/ubuntu
URIs: https://mirrors.tuna.tsinghua.edu.cn/mariadb/repo/11.8/ubuntu
Suites: noble
Components: main main/debug
Signed-By: /etc/apt/keyrings/mariadb-keyring.pgp
EOF
root@ubuntu2404:~# apt update
root@ubuntu2404:~# apt install -y mariadb-server
root@ubuntu2404:~# systemctl enable --now mariadb
root@ubuntu2404:~# ls /var/lib/mysql/
aria_log.00000001 debian-11.8.flag ib_logfile0 multi-master.info sys undo002
aria_log_control ib_buffer_pool ibtmp1 mysql tc.log undo003
ddl_recovery.log ibdata1 mariadb_upgrade_info performance_schema undo001
root@ubuntu2404:~# mariadb -V
mariadb from 11.8.3-MariaDB, client 15.2 for debian-linux-gnu (x86_64) using EditLine wrapper
root@ubuntu2404:~# systemctl status mariadb
● mariadb.service - MariaDB 11.8.3 database server
Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; preset: enabled)
Drop-In: /etc/systemd/system/mariadb.service.d
└─migrated-from-my.cnf-settings.conf
Active: active (running) since Sun 2025-08-17 12:21:22 CST; 1min 1s ago
Docs: man:mariadbd(8)
https://mariadb.com/kb/en/library/systemd/
Main PID: 2588 (mariadbd)
Status: "Taking your SQL requests now..."
Tasks: 10 (limit: 14588)
Memory: 93.0M (peak: 97.2M)
CPU: 2.489s
CGroup: /system.slice/mariadb.service
└─2588 /usr/sbin/mariadbd
Aug 17 12:21:21 ubuntu2404 mariadbd[2588]: 2025-08-17 12:21:21 0 [Note] Plugin 'FEEDBACK' is disabled.
Aug 17 12:21:21 ubuntu2404 mariadbd[2588]: 2025-08-17 12:21:21 0 [Note] InnoDB: Loading buffer pool(s) from /var>
Aug 17 12:21:21 ubuntu2404 mariadbd[2588]: 2025-08-17 12:21:21 0 [Note] Plugin 'wsrep-provider' is disabled.
Aug 17 12:21:21 ubuntu2404 mariadbd[2588]: 2025-08-17 12:21:21 0 [Note] InnoDB: Buffer pool(s) load completed at>
Aug 17 12:21:22 ubuntu2404 mariadbd[2588]: 2025-08-17 12:21:22 0 [Note] Server socket created on IP: '127.0.0.1'>
Aug 17 12:21:22 ubuntu2404 mariadbd[2588]: 2025-08-17 12:21:22 0 [Note] mariadbd: Event Scheduler: Loaded 0 even>
Aug 17 12:21:22 ubuntu2404 mariadbd[2588]: 2025-08-17 12:21:22 0 [Note] /usr/sbin/mariadbd: ready for connection>
Aug 17 12:21:22 ubuntu2404 mariadbd[2588]: Version: '11.8.3-MariaDB-ubu2404' socket: '/run/mysqld/mysqld.sock' >
Aug 17 12:21:22 ubuntu2404 systemd[1]: Started mariadb.service - MariaDB 11.8.3 database server.
Aug 17 12:21:22 ubuntu2404 /etc/mysql/debian-start[2621]: Triggering myisam-recover for all MyISAM tables and ar>
root@ubuntu2404:~# mariadb
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 31
Server version: 11.8.3-MariaDB-ubu2404 mariadb.org binary distribution
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)]> status
--------------
mariadb from 11.8.3-MariaDB, client 15.2 for debian-linux-gnu (x86_64) using EditLine wrapper
Connection id: 31
Current database:
Current user: root@localhost
SSL: Cipher in use is TLS_AES_256_GCM_SHA384, cert is OK
Current pager: stdout
Using outfile: ''
Using delimiter: ;
Server: MariaDB
Server version: 11.8.3-MariaDB-ubu2404 mariadb.org binary distribution
Protocol version: 10
Connection: Localhost via UNIX socket
Server characterset: utf8mb4
Db characterset: utf8mb4
Client characterset: utf8mb4
Conn. characterset: utf8mb4
UNIX socket: /run/mysqld/mysqld.sock
Uptime: 1 min 26 sec
Threads: 1 Questions: 61 Slow queries: 0 Opens: 33 Open tables: 26 Queries per second avg: 0.709
--------------
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.001 sec)
MariaDB [(none)]> select user,host from mysql.user;
+-------------+-----------+
| User | Host |
+-------------+-----------+
| mariadb.sys | localhost |
| mysql | localhost |
| root | localhost |
+-------------+-----------+
3 rows in set (0.001 sec)
MariaDB [(none)]> exit
Bye
添加官方资源库,去“https://mariadb.org”网站下载,选择“Download”。
图6 MariaDB首页
在打开的网页,在“MariaDB Server Repositories”下面选择“Choose a distribution为:24.04 "noble"”,选择“Choose a MariaDB Server version为:11.8”,选择“Mirror为:清华大学 TUNA 协会 (Tsinghua University TUNA Association)”,然后根据下面提示操作。
图7 MariaDB添加资源库
rpm --import https://mirrors.tuna.tsinghua.edu.cn/mariadb/yum/RPM-GPG-KEY-MariaDB
zypper addrepo --gpgcheck --refresh https://mirrors.tuna.tsinghua.edu.cn/mariadb/yum/11.8/sles/\$releasever/\$basearch mariadb
zypper --gpg-auto-import-keys refresh
opensuse15:~ # zypper install -y MariaDB-server
opensuse15:~ # systemctl enable --now mariadb
opensuse15:~ # ls /var/lib/mysql/
aria_log.00000001 ib_buffer_pool ibtmp1 mysql performance_schema test undo003
aria_log_control ib_logfile0 mariadb_upgrade_info mysql.sock sys undo001
ddl_recovery.log ibdata1 multi-master.info opensuse15.pid tc.log undo002
opensuse15:~ # mariadb -V
mariadb from 11.8.3-MariaDB, client 15.2 for Linux (x86_64) using readline 5.1
opensuse15:~ # systemctl status mariadb
● mariadb.service - MariaDB 11.8.3 database server
Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; preset: disabled)
Drop-In: /etc/systemd/system/mariadb.service.d
└─migrated-from-my.cnf-settings.conf
Active: active (running) since Sun 2025-08-17 12:44:32 CST; 51s ago
Docs: man:mariadbd(8)
https://mariadb.com/kb/en/library/systemd/
Process: 14079 ExecStartPre=/bin/sh -c [ ! -e /usr/bin/galera_recovery ] && VAR= || VAR=`/usr/bin/galera_r>
Process: 14099 ExecStartPost=/bin/rm -f /var/lib/mysql/wsrep-start-position (code=exited, status=0/SUCCESS)
Main PID: 14087 (mariadbd)
Status: "Taking your SQL requests now..."
Tasks: 11 (limit: 14850)
CPU: 687ms
CGroup: /system.slice/mariadb.service
└─14087 /usr/sbin/mariadbd
Aug 17 12:44:31 opensuse15 mariadbd[14087]: 2025-08-17 12:44:31 0 [Note] Plugin 'FEEDBACK' is disabled.
Aug 17 12:44:31 opensuse15 mariadbd[14087]: 2025-08-17 12:44:31 0 [Note] Plugin 'wsrep-provider' is disabled.
Aug 17 12:44:31 opensuse15 mariadbd[14087]: 2025-08-17 12:44:31 0 [Note] InnoDB: Loading buffer pool(s) from /va>
Aug 17 12:44:31 opensuse15 mariadbd[14087]: 2025-08-17 12:44:31 0 [Note] InnoDB: Buffer pool(s) load completed a>
Aug 17 12:44:32 opensuse15 mariadbd[14087]: 2025-08-17 12:44:32 0 [Note] Server socket created on IP: '0.0.0.0',>
Aug 17 12:44:32 opensuse15 mariadbd[14087]: 2025-08-17 12:44:32 0 [Note] Server socket created on IP: '::', port>
Aug 17 12:44:32 opensuse15 mariadbd[14087]: 2025-08-17 12:44:32 0 [Note] mariadbd: Event Scheduler: Loaded 0 eve>
Aug 17 12:44:32 opensuse15 mariadbd[14087]: 2025-08-17 12:44:32 0 [Note] /usr/sbin/mariadbd: ready for connectio>
Aug 17 12:44:32 opensuse15 mariadbd[14087]: Version: '11.8.3-MariaDB' socket: '/var/lib/mysql/mysql.sock' port>
Aug 17 12:44:32 opensuse15 systemd[1]: Started MariaDB 11.8.3 database server.
opensuse15:~ # mariadb
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 11.8.3-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)]> status
--------------
mariadb from 11.8.3-MariaDB, client 15.2 for Linux (x86_64) using readline 5.1
Connection id: 3
Current database:
Current user: root@localhost
SSL: Cipher in use is TLS_AES_256_GCM_SHA384, cert is OK
Current pager: less
Using outfile: ''
Using delimiter: ;
Server: MariaDB
Server version: 11.8.3-MariaDB MariaDB Server
Protocol version: 10
Connection: Localhost via UNIX socket
Server characterset: utf8mb4
Db characterset: utf8mb4
Client characterset: utf8mb4
Conn. characterset: utf8mb4
UNIX socket: /var/lib/mysql/mysql.sock
Uptime: 1 min 16 sec
Threads: 1 Questions: 4 Slow queries: 0 Opens: 17 Open tables: 10 Queries per second avg: 0.052
--------------
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
| test | # 有test数据库
+--------------------+
5 rows in set (0.000 sec)
MariaDB [(none)]> select user,host from mysql.user;
+-------------+------------+
| User | Host |
+-------------+------------+
| PUBLIC | |
| | localhost | # 有匿名用户
| mariadb.sys | localhost |
| mysql | localhost |
| root | localhost |
| | opensuse15 | # 有远程登录用户
+-------------+------------+
6 rows in set (0.001 sec)
MariaDB [(none)]> exit
Bye
# 有test数据库、匿名用户和远程登录用户,需要安全初始化
opensuse15:~ # 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): # 输入 root 的当前密码(不输入),直接敲回车
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 # 输入y,切换到 unix_socket 身份验证
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] n # 输入n,不设置root密码
... 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 # 输入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 # 输入y,禁止 root 远程登录
... 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 # 输入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 # 输入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!
opensuse15:~ # mariadb
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 14
Server version: 11.8.3-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)]> status
--------------
mariadb from 11.8.3-MariaDB, client 15.2 for Linux (x86_64) using readline 5.1
Connection id: 14
Current database:
Current user: root@localhost
SSL: Cipher in use is TLS_AES_256_GCM_SHA384, cert is OK
Current pager: less
Using outfile: ''
Using delimiter: ;
Server: MariaDB
Server version: 11.8.3-MariaDB MariaDB Server
Protocol version: 10
Connection: Localhost via UNIX socket
Server characterset: utf8mb4
Db characterset: utf8mb4
Client characterset: utf8mb4
Conn. characterset: utf8mb4
UNIX socket: /var/lib/mysql/mysql.sock
Uptime: 2 min 35 sec
Threads: 1 Questions: 30 Slow queries: 0 Opens: 18 Open tables: 11 Queries per second avg: 0.193
--------------
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.000 sec)
# 没有test数据库
MariaDB [(none)]> select user,host from mysql.user;
+-------------+-----------+
| User | Host |
+-------------+-----------+
| PUBLIC | |
| mariadb.sys | localhost |
| mysql | localhost |
| root | localhost |
+-------------+-----------+
4 rows in set (0.001 sec)
# 没有匿名用户和远程登录用户
MariaDB [(none)]> exit
Bye
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。