源码包安装mariadb

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就到此结束啦!!!

  • 36
    点赞
  • 23
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
要在Ubuntu上安装MariaDB二进制tar,你可以按照以下步骤进行操作: 1. 首先,打开终端窗口,并在系统上安装必要的依赖项。使用以下命令更新软件列表并安装所需的依赖项: ``` sudo apt update sudo apt install libaio1 libmecab2 ``` 2. 接下来,你需要从MariaDB官方网站(https://mariadb.org)下载适用于Ubuntu的二进制tar。下载后,你可以将该文件放在某个目录中,例如`/tmp`。可以使用以下命令进行下载: ``` wget https://downloads.mariadb.org/interstitial/mariadb-10.6.5/bintar-linux-x86_64/mariadb-10.6.5-linux-x86_64.tar.gz -P /tmp ``` 3. 解压下载的tar。在终端中使用以下命令: ``` sudo tar xf /tmp/mariadb-10.6.5-linux-x86_64.tar.gz -C /usr/local ``` 4. 添加MariaDB到环境变量中。打开`~/.bashrc`文件,将以下行添加到文件末尾: ``` export PATH=/usr/local/mariadb-10.6.5-linux-x86_64/bin:$PATH ``` 5. 保存文件并关闭。然后,使用以下命令使更改生效: ``` source ~/.bashrc ``` 6. 现在,你可以启动MariaDB服务器。在终端中使用以下命令: ``` sudo /usr/local/mariadb-10.6.5-linux-x86_64/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mariadb-10.6.5-linux-x86_64/ --datadir=/var/lib/mysql ``` 7. 安装完成后,你可以使用以下命令启动MariaDB服务器: ``` sudo /usr/local/mariadb-10.6.5-linux-x86_64/bin/mysqld_safe --datadir=/var/lib/mysql & ``` 8. 最后,你可以使用以下命令登录到MariaDB控制台: ``` sudo /usr/local/mariadb-10.6.5-linux-x86_64/bin/mysql -u root -p ``` 以上就是在Ubuntu上安装MariaDB二进制tar的步骤。请根据自己的需求进行相应的调整和配置。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值