源码包安装mariadb

本文涉及的产品
云数据库 RDS MySQL Serverless,0.5-2RCU 50GB
云数据库 RDS MySQL Serverless,价值2615元额度,1个月
简介: **MariaDB**是MySQL的一个开源分支,由社区维护,提供高性能、安全且与MySQL高度兼容的数据库解决方案。它使用XtraDB和Maria存储引擎替代InnoDB和MyISAM。特点是开源、高性能、兼容性和安全性,广泛应用于各种场景和操作系统。在Redhat 9.2上安装MariaDB 10.6.17,首先配置yum源,检查现有MySQL/MariaDB,安装依赖包,下载源码,解压并配置编译环境,使用cmake和make编译安装,初始化数据库,创建用户,设置密码,添加启动脚本至开机自启,并执行安全初始化设置。


mariadb简介
MariaDB是一个开源的数据库管理系统,它是MySQL的一个分支,主要由开源社区进行维护。MariaDB的目标是提供一个高性能、可靠且易于使用的数据库解决方案,同时保持与MySQL的高度兼容性,以便能够无缝地替换MySQL。

在存储引擎方面,MariaDB使用XtraDB来代替MySQL的InnoDB,这是InnoDB的一个变体,开发者希望它能提供访问即将到来的MySQL 5.4 InnoDB性能。此外,MariaDB还基于事务的Maria存储引擎替换了MySQL的MyISAM存储引擎。

MariaDB的特点包括开源免费、高性能、兼容性和安全性。用户可以自由地使用、修改和分发MariaDB,节省了大量的许可费用,并能根据自己的需求进行定制开发。MariaDB采用了多种技术来提高查询性能,包括索引优化、缓存管理和并发控制等,使其在处理大量数据和高并发访问时表现出色。同时,由于MariaDB与MySQL的高度兼容性,用户可以方便地将现有的MySQL应用迁移到MariaDB,而无需进行大量的代码修改。在安全性方面,MariaDB提供了数据加密、访问控制和审计日志等特性,帮助用户保护敏感数据。

MariaDB适用于各种不同的场景,包括Web应用程序、大型企业应用、移动应用、电子商务网站、金融和医疗领域等。它可以在多种操作系统上运行,如Linux、Windows、macOS等,并可以与许多其他技术和应用程序集成,如PHP、Java、Python、Ruby等。

最新版本的MariaDB(如MariaDB 10.11)带来了许多新特性和改进,旨在提供更好的性能和稳定性。这些新版本通常会在发布后进行长期的维护和支持,以确保用户能够稳定地使用。

总的来说,MariaDB是一个功能强大、灵活且安全的数据库管理系统,适用于各种规模和需求的应用场景。

安装环境
Redhat 9.2

mariadb 10.6.17

安装步骤
1、配置本地yum源
[root@localhost mnt]# mount /dev/sr1 /mnt/
mount: /mnt: WARNING: source write-protected, mounted read-only.
[root@localhost ~]# vim /etc/yum.repos.d/server.repo
[a]
name=aa
baseurl=file:///mnt/AppStream
gpgcheck=0
enabled=1
[b]
name=bb
baseurl=file:///mnt/BaseOS
gpgcheck=0
enabled=1
[root@localhost mnt]# yum clean all
Updating Subscription Management repositories.
Unable to read consumer identity

This system is not registered with an entitlement server. You can use subscription-manager to register.

0 files removed
[root@localhost mnt]# yum makecache
Updating Subscription Management repositories.
Unable to read consumer identity

This system is not registered with an entitlement server. You can use subscription-manager to register.

aa 127 MB/s | 6.3 MB 00:00
bb 87 MB/s | 1.7 MB 00:00
Metadata cache created.
2、检查是否有mariadb和MySQL
[root@localhost ~]# rpm -qa | grep mariadb
[root@localhost ~]# rpm -qa | grep mysql
3、安装依赖包
[root@localhost ~]# dnf install -y wget bison zlib-devel libcurl-devel boost-devel gcc gcc-c++ cmake ncurses-devel gnutls-devel libxml2-devel openssl-devel libevent-devel libaio-devel make

省略。。。。。

Installed:
bison-3.7.4-5.el9.x86_64 boost-1.75.0-8.el9.x86_64 boost-atomic-1.75.0-8.el9.x86_64
boost-chrono-1.75.0-8.el9.x86_64 boost-container-1.75.0-8.el9.x86_64 boost-context-1.75.0-8.el9.x86_64
boost-contract-1.75.0-8.el9.x86_64 boost-coroutine-1.75.0-8.el9.x86_64 boost-date-time-1.75.0-8.el9.x86_64
boost-devel-1.75.0-8.el9.x86_64 boost-fiber-1.75.0-8.el9.x86_64 boost-filesystem-1.75.0-8.el9.x86_64
boost-graph-1.75.0-8.el9.x86_64 boost-iostreams-1.75.0-8.el9.x86_64 boost-locale-1.75.0-8.el9.x86_64
boost-log-1.75.0-8.el9.x86_64 boost-math-1.75.0-8.el9.x86_64 boost-nowide-1.75.0-8.el9.x86_64
boost-numpy3-1.75.0-8.el9.x86_64 boost-program-options-1.75.0-8.el9.x86_64 boost-python3-1.75.0-8.el9.x86_64
boost-random-1.75.0-8.el9.x86_64 boost-regex-1.75.0-8.el9.x86_64 boost-serialization-1.75.0-8.el9.x86_64
boost-stacktrace-1.75.0-8.el9.x86_64 boost-system-1.75.0-8.el9.x86_64 boost-test-1.75.0-8.el9.x86_64
boost-thread-1.75.0-8.el9.x86_64 boost-timer-1.75.0-8.el9.x86_64 boost-type_erasure-1.75.0-8.el9.x86_64
boost-wave-1.75.0-8.el9.x86_64 cmake-3.20.2-8.el9.x86_64 cmake-data-3.20.2-8.el9.noarch
cmake-filesystem-3.20.2-8.el9.x86_64 cmake-rpm-macros-3.20.2-8.el9.noarch flexiblas-3.0.4-8.el9.x86_64
flexiblas-netlib-3.0.4-8.el9.x86_64 flexiblas-openblas-openmp-3.0.4-8.el9.x86_64 gcc-11.3.1-4.3.el9.x86_64
gcc-c++-11.3.1-4.3.el9.x86_64 glibc-devel-2.34-60.el9.x86_64 glibc-headers-2.34-60.el9.x86_64
gmp-c++-1:6.2.0-10.el9.x86_64 gmp-devel-1:6.2.0-10.el9.x86_64 gnutls-c++-3.7.6-20.el9_2.x86_64
gnutls-dane-3.7.6-20.el9_2.x86_64 gnutls-devel-3.7.6-20.el9_2.x86_64 kernel-headers-5.14.0-284.11.1.el9_2.x86_64
libaio-devel-0.3.111-13.el9.x86_64 libcurl-devel-7.76.1-23.el9.x86_64 libevent-devel-2.1.12-6.el9.x86_64
libgfortran-11.3.1-4.3.el9.x86_64 libicu-devel-67.1-9.el9.x86_64 libidn2-devel-2.3.0-7.el9.x86_64
libquadmath-11.3.1-4.3.el9.x86_64 libquadmath-devel-11.3.1-4.3.el9.x86_64 libstdc++-devel-11.3.1-4.3.el9.x86_64
libtasn1-devel-4.16.0-8.el9_1.x86_64 libtasn1-tools-4.16.0-8.el9_1.x86_64 libxcrypt-devel-4.4.18-3.el9.x86_64
libxml2-devel-2.9.13-3.el9_1.x86_64 m4-1.4.19-1.el9.x86_64 make-1:4.3-7.el9.x86_64
ncurses-c++-libs-6.2-8.20210508.el9.x86_64 ncurses-devel-6.2-8.20210508.el9.x86_64 nettle-devel-3.8-3.el9_0.x86_64
openblas-0.3.21-2.el9.x86_64 openblas-openmp-0.3.21-2.el9.x86_64 openssl-devel-1:3.0.7-6.el9_2.x86_64
p11-kit-devel-0.24.1-2.el9.x86_64 python3-numpy-1:1.20.1-5.el9.x86_64 unbound-libs-1.16.2-3.el9.x86_64
xz-devel-5.2.5-8.el9_0.x86_64 zlib-devel-1.2.11-39.el9.x86_64

Complete!
4、下载MariaDB源码包
mariadb官网:Download MariaDB Server - MariaDB.org

[root@localhost ~]# wget -c https://ftp.yz.yamagata-u.ac.jp/pub/dbms/mariadb//mariadb-10.6.17/source/mariadb-10.6.17.tar.gz
--2024-04-13 18:09:32-- https://ftp.yz.yamagata-u.ac.jp/pub/dbms/mariadb//mariadb-10.6.17/source/mariadb-10.6.17.tar.gz
Resolving ftp.yz.yamagata-u.ac.jp (ftp.yz.yamagata-u.ac.jp)... 133.24.248.17, 133.24.248.16, 133.24.248.18, ...
Connecting to ftp.yz.yamagata-u.ac.jp (ftp.yz.yamagata-u.ac.jp)|133.24.248.17|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 99067793 (94M) [application/x-gzip]
Saving to: ‘mariadb-10.6.17.tar.gz’

mariadb-10.6.17.tar.gz 100%[========================================================================>] 94.48M 21.0MB/s in 6.8s

2024-04-13 18:09:40 (13.9 MB/s) - ‘mariadb-10.6.17.tar.gz’ saved [99067793/99067793]

[root@localhost ~]#
5、解压源码包
创建一个目录存放解压的源码包,再解压

[root@localhost ~]# mkdir mariadb_up
[root@localhost ~]# tar -xvf mariadb-10.6.17.tar.gz -C mariadb_up/
mariadb-10.6.17/
mariadb-10.6.17/configure.cmake
mariadb-10.6.17/vio/
mariadb-10.6.17/vio/viotest.cc
mariadb-10.6.17/vio/test-sslclient.c
mariadb-10.6.17/vio/viosocket.c
mariadb-10.6.17/vio/viotest-ssl.c
mariadb-10.6.17/vio/docs/
mariadb-10.6.17/vio/docs/INSTALL
mariadb-10.6.17/vio/docs/COPYING.openssl
省略。。。。。
6、配置编译环境
进入解压目录,使用cmake进行配置,然后使用make编译

[root@localhost ~]# cd mariadb_up/mariadb-10.6.17/
[root@localhost mariadb-10.6.17]#
[root@localhost mariadb-10.6.17]# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \ //指定主配置文件目录
-DMYSQL_DATADIR=/usr/local/mysql/data \ //指定库文件目录
-DSYSCONFDIR=/etc \ //指定配置文件目录
-DWITH_INNOBASE_STORAGE_ENGINE=1 \ //启用innoDB引擎
-DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_READLINE=1 \
-DWITH_SSL=system -DWITH_ZLIB=system -DDEFAULT_CHARSET=utf8 \ //utf8编码
-DDEFAULT_COLLATION=utf8_general_ci //默认字符集规则

-- The C compiler identification is GNU 11.3.1
-- The CXX compiler identification is GNU 11.3.1
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info -
省略。。。。。
7、编译安装
使用make命令进行编译,然后使用make install命令进行安装

[root@localhost mariadb-10.6.17]# make && make install
[ 0%] Built target abi_check
[ 0%] Built target INFO_SRC
[ 0%] Built target INFO_BIN
[ 0%] Building C object wsrep-lib/wsrep-API/CMakeFiles/wsrep_api_v26.dir/v26/wsrep_dummy.c.o
[ 0%] Building C object wsrep-lib/wsrep-API/CMakeFiles/wsrep_api_v26.dir/v26/wsrep_gtid.c.o
[ 0%] Building C object wsrep-lib/wsrep-API/CMakeFiles/wsrep_api_v26.dir/v26/wsrep_loader.c.o
[ 0%] Building C object wsrep-lib/wsrep-API/CMakeFiles/wsrep_api_v26.dir/v26/wsrep_uuid.c.o
[ 0%] Linking C static library libwsrep_api_v26.a
[ 0%] Built target wsrep_api_v26
省略 。。。。。(耐心等待大约30分钟左右)

-- Installing: /usr/local/mysql/support-files/policy/selinux/mariadb.te
-- Installing: /usr/local/mysql/support-files/policy/selinux/mariadb-server.fc
-- Installing: /usr/local/mysql/support-files/policy/selinux/mariadb.pp
-- Installing: /usr/local/mysql/lib/pkgconfig/mariadb.pc
-- Installing: /usr/local/mysql/share/aclocal/mysql.m4
-- Installing: /usr/local/mysql/support-files/mysql.server
8、初始化数据库配置
创建mysql用户、再初始化数据库

[root@localhost ~]# useradd -s /sbin/nologin mysql
[root@localhost ~]# getent passwd mysql
mysql:x:1001:1001::/home/mysql:/sbin/nologin
[root@localhost ~]#

参数解释 --user指定用户 --basedir指定基础配置文件目录 --datadir指数据库文件存储目录

[root@localhost mysql]# scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
Installing MariaDB/MySQL system tables in '/usr/local/mysql/data' ...
OK

To start mariadbd at boot time you have to copy
support-files/mariadb.service to the right place for your system

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

You can start the MariaDB daemon with:
cd '/usr/local/mysql' ; /usr/local/mysql/bin/mariadbd-safe --datadir='/usr/local/mysql/data'

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

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/

[root@localhost mysql]#
9、把启动脚本放到开机初始化目录
安装命令包添加MySQL服务

[root@localhost ~]# /usr/local/mysql/support-files/mysql.server restart //重启服务测试
Shutting down MariaDB. SUCCESS!
Starting MariaDB.240413 20:44:21 mysqld_safe Logging to '/usr/local/mysql/data/localhost.localdomain.err'.
240413 20:44:21 mysqld_safe Starting mariadbd daemon with databases from /usr/local/mysql/data
SUCCESS!
[root@localhost ~]#
[root@localhost ~]# cd /usr/local/mysql/support-files/
[root@localhost support-files]#
[root@localhost support-files]# cp mysql.server /etc/rc.d/init.d/mysql
[root@localhost support-files]# cd /etc/rc.d/init.d/
[root@localhost init.d]# ls
mysql README
[root@localhost init.d]#
[root@localhost init.d]# yum -y install chkconfig.x86_64 //安装系统启动时自动添加和配置服务
Updating Subscription Management repositories.
Unable to read consumer identity

This system is not registered with an entitlement server. You can use subscription-manager to register.

Last metadata expiration check: 2:08:29 ago on Sat 13 Apr 2024 06:27:41 PM CST.

Dependencies resolved.

Package Architecture Version Repository Size

Installing:
chkconfig x86_64
省略 。。。。
Installed:
chkconfig-1.20-2.el9.x86_64

Complete!
[root@localhost init.d]# chkconfig --add mysql //添加MySQL服务
[root@localhost init.d]# cd
[root@localhost ~]# service mysql restart
Shutting down MariaDB. SUCCESS!
Starting MariaDB.240413 21:01:00 mysqld_safe Logging to '/usr/local/mysql/data/localhost.localdomain.err'.
240413 21:01:00 mysqld_safe Starting mariadbd daemon with databases from /usr/local/mysql/data
SUCCESS!
[root@localhost ~]# /usr/local/mysql/bin/mysql //进入MySQL此时不需要密码
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 7
Server version: 10.6.17-MariaDB Source 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)]>
10、初始化MySQL

[root@localhost ~]# /usr/local/mysql/bin/mysql_secure_installation //初始化mysql

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] n //是否切换到unix_socket身份验证
... skipping.

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

Change the root password? [Y/n] y //设置root密码
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 //是否允许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 //是否移除test数据库

  • 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@localhost ~]#
[root@localhost ~]# /usr/local/mysql/bin/mysql -uroot -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 5
Server version: 10.6.17-MariaDB Source 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)]> exit
[root@localhost ~]# /usr/local/mysql/bin/mysql -uroot -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 5
Server version: 10.6.17-MariaDB Source 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)]> exirt
Bye
源码包编译mariadb就到此结束啦!!!

相关实践学习
基于CentOS快速搭建LAMP环境
本教程介绍如何搭建LAMP环境,其中LAMP分别代表Linux、Apache、MySQL和PHP。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助     相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
目录
相关文章
|
7月前
|
关系型数据库 MySQL Linux
Linux(centos 7.5)服务器安装MariaDB
Linux(centos 7.5)服务器安装MariaDB
205 0
|
2月前
|
网络协议 关系型数据库 MySQL
安卓手机termux上安装MariaDB数据库并实现公网环境下的远程连接
安卓手机termux上安装MariaDB数据库并实现公网环境下的远程连接
|
8月前
|
关系型数据库 Linux 网络安全
Linux系统下安装mariaDB数据库及防火墙
Linux系统下安装mariaDB数据库及防火墙
116 0
|
5月前
|
SQL 关系型数据库 MySQL
centos编译安装mariadb
一般我不太愿意用mysql,那个玩意,有的时候不太友好。 我还是比较喜欢mariadb。
140 0
|
9月前
|
存储 关系型数据库 MySQL
mysql--Centos安装MariaDB(mysql)
mysql--Centos安装MariaDB(mysql)
1386 0
|
9月前
|
Ubuntu 关系型数据库 MySQL
Ubuntu安装MariaDB-10.3数据库(等同于Mysql-5.7)
Ubuntu安装MariaDB-10.3数据库(等同于Mysql-5.7)
197 0
|
7月前
|
NoSQL 关系型数据库 MySQL
阿里云RDS关系型数据库大全_MySQL版、PolarDB、PostgreSQL、SQL Server和MariaDB等
阿里云RDS关系型数据库如MySQL版、PolarDB、PostgreSQL、SQL Server和MariaDB等,NoSQL数据库如Redis、Tair、Lindorm和MongoDB
254 0
|
7月前
|
NoSQL 关系型数据库 MySQL
阿里云关系型数据库详细介绍MySQL/MariaDB/SQL Server/PolarDB/PostgreSQL等
阿里云关系型数据库详细介绍MySQL/MariaDB/SQL Server/PolarDB/PostgreSQL等,阿里云RDS关系型数据库如MySQL版、PolarDB、PostgreSQL、SQL Server和MariaDB等
118 0
|
7月前
|
NoSQL Cloud Native 关系型数据库
阿里云RDS数据库_MySQL_SQL Server_MariaDB_PolarDB_PostgreSQL
阿里云RDS关系型数据库大全:MySQL版、PolarDB、PostgreSQL、SQL Server和MariaDB等
111 0
|
存储 自然语言处理 关系型数据库
mysql/mariadb 实现全文检索
mysql/mariadb 实现全文检索
mysql/mariadb 实现全文检索

推荐镜像

更多