官方源码包安装MariaDB-server10.6.8

文章目录

  • 官方源码包安装MariaDB-server10.6.8
    • 1、下载源码包,解压文件
    • 2、安装依赖和创建运行用户
    • 3、编译安装
    • 4、修改环境变量
    • 5、初始化数据库,默认以root用户登录,初始无密码
    • 6、启动测试
    • 7、修改root用户密码
    • 8、开放远程连接,要有这个用户'root'@'%'

官方源码包安装MariaDB-server10.6.8

1、下载源码包,解压文件

下载地址:https://mariadb.org/download/?t=mariadb&p=mariadb&r=10.6.8&os=source&m=xtom_hk

mariadb-10.6.8源码下载:https://ftp.bme.hu/pub/mirrors/mariadb//mariadb-10.6.8/source/mariadb-10.6.8.tar.gz
[root@server ~]# ll mariadb-10.6.8.tar.gz 
-rw-r--r--. 1 root root 88794744 May 29 04:28 mariadb-10.6.8.tar.gz
[root@server ~]# tar xf mariadb-10.6.8.tar.gz -C /usr/local/            # 注意解压的时候,不要解压到安装目录中
[root@server ~]# cd /usr/local/mariadb-10.6.8/
[root@server mariadb-10.6.8]# ls
appveyor.yml     debian              mysys          tests
BUILD            Docs                mysys_ssl      THIRDPARTY
BUILD-CMAKE      extra               plugin         tpool
client           include             randgen        unittest
cmake            INSTALL-SOURCE      README.md      VERSION
CMakeLists.txt   INSTALL-WIN-SOURCE  scripts        vio
config.h.cmake   KNOWN_BUGS.txt      sql            win
configure.cmake  libmariadb          sql-bench      wsrep-lib
CONTRIBUTING.md  libmysqld           sql-common     zlib
COPYING          libservices         storage
CREDITS          man                 strings
dbug             mysql-test          support-files

2、安装依赖和创建运行用户

# 安装依赖
[root@server ~]# yum -y install bison bison-devel zlib-devel libcurl-devel libarchive-devel boost-devel gcc gcc-c++ libevent-devel gnutls-devel libaio-devel openssl-devel ncurses-devel libxml2-devel 

# 创建运行用户
[root@server ~]# useradd -s /sbin/nologin mysql
[root@server ~]# id mysql
uid=1001(mysql) gid=1001(mysql) groups=1001(mysql)

3、编译安装

[root@server ~]# cd /usr/local/mariadb-10.6.8/
# 预编译
[root@server mariadb-10.6.8]# cmake . \ 
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/data/mysqldb/ \
-DSYSCONFDIR=/etc \
-DMYSQL_USER=mysql \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1  \
-DWITHOUT_MROONGA_STORAGE_ENGINE=1 \
-DWITH_DEBUG=0 \
-DWITH_READLINE=1 \
-DWITH_SSL=system \
-DWITH_ZLIB=system \
-DWITH_LIBWRAP=0 \
-DENABLED_LOCAL_INFILE=1  \
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITHOUT_TOKUDB=1
-- Configuring done
-- Generating done
-- Build files have been written to: /usr/local/mysql
[root@server mysql]# make -j 4 && make install    # 编译,并安装
# 若有以下报错,可以单独下载这个文件后再次编译。
-- downloading...    # 单独下载
     src='https://github.com/fmtlib/fmt/archive/refs/tags/8.0.1.zip'
     dst='/usr/local/mysql/extra/libfmt/src/8.0.1.zip'
    for file: [/usr/local/mysql/extra/libfmt/src/8.0.1.zip]
      expected hash: [e77873199e897ca9f780479ad68e25b1]
        actual hash: [d41d8cd98f00b204e9800998ecf8427e]
-- downloading...    # 单独下载
     src='https://github.com/PhilipHazel/pcre2/releases/download/pcre2-10.40/pcre2-10.40.zip'
     dst='/usr/local/mysql/extra/pcre2/src/pcre2-10.40.zip'
    for file: [/usr/local/mysql/extra/pcre2/src/pcre2-10.40.zip]
      expected hash: [798698846982ce171d881ed0d7535c2a]
        actual hash: [d41d8cd98f00b204e9800998ecf8427e]
-- Detecting C compiler ABI info - done    # CMake版本太低,升级下
Scanning dependencies of target client_ed25519
CMake Error at CMakeLists.txt:107 (CMAKE_MINIMUM_REQUIRED):
  CMake 3.0.0 or higher is required.  You are running version 2.8.12.2
# 升级cmake
# 下载解压
wget https://cmake.org/files/v3.0/cmake-3.0.0.tar.gz
tar xvf cmake-3.0.0.tar.gz -C /usr/local && cd /usr/local/cmake-3.0.0
# 编译安装
./bootstrap
gmake
gmake install
/usr/local/bin/cmake --version    # 查看版本
yum remove cmake -y   # 卸载旧版cmake
ln -s /usr/local/bin/cmake /usr/bin/   # 软链接
cmake --version   # 查看版本
[root@server ~]# cmake --version
cmake version 3.0.0

4、修改环境变量

# 修改PATH环境变量,便于执行mysql命令
[root@server ~]# echo "export PATH=/usr/local/mysql/bin:\$PATH" >/etc/profile.d/mysql.sh
[root@server ~]# cat /etc/profile.d/mysql.sh
export PATH=/usr/local/mysql/bin:$PATH
[root@server ~]# . /etc/profile.d/mysql.sh
[root@server ~]# setfacl -R -m u:mysql:rwx /usr/local/mysql/

5、初始化数据库,默认以root用户登录,初始无密码

# 初始化数据库
[root@server ~]# cd /usr/local/mysql/
[root@server mysql]# scripts/mysql_install_db --datadir=/data/mysqldb/ --user=mysql --basedir=/usr/local/mysql/
[root@server mysql]# cp support-files/wsrep.cnf /etc/my.cnf
[root@server mysql]# cp support-files/mysql.server /etc/init.d/mysqld
[root@server mysql]# chkconfig --add mysqld   # mysqld服务添加到chkconfig,方便使用service命令启动。

6、启动测试

[root@server mysql]# service mysqld start
Starting mysqld (via systemctl):                           [  OK  ]
[root@server mysql]# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 4
Server version: 10.6.8-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)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
| test               |
+--------------------+
5 rows in set (0.001 sec)

7、修改root用户密码

MariaDB [mysql]> select Host,User,Password,authentication_string from user;    # 查看当前的用户情况
+-----------+-------------+----------+-----------------------+
| Host      | User        | Password | authentication_string |
+-----------+-------------+----------+-----------------------+
| localhost | mariadb.sys |          |                       |
| localhost | root        | invalid  | invalid               |
| localhost | mysql       | invalid  | invalid               |
| localhost |             |          |                       |
| server    |             |          |                       |
+-----------+-------------+----------+-----------------------+
5 rows in set (0.001 sec)
MariaDB [mysql]> grant all privileges on *.* to 'root'@'%' identified by '123456';     # 修改用户密码和权限
Query OK, 0 rows affected (0.001 sec)

MariaDB [mysql]> grant all privileges on *.* to 'root'@'localhost' identified by '123456';   # 修改用户密码和权限
Query OK, 0 rows affected (0.001 sec)

MariaDB [mysql]> select Host,User,Password,authentication_string from user;
+-----------+-------------+-------------------------------------------+-------------------------------------------+
| Host      | User        | Password                                  | authentication_string                     |
+-----------+-------------+-------------------------------------------+-------------------------------------------+
| localhost | mariadb.sys |                                           |                                           |
| localhost | root        | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| localhost | mysql       | invalid                                   | invalid                                   |
| localhost |             |                                           |                                           |
| server    |             |                                           |                                           |
| %         | root        | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
+-----------+-------------+-------------------------------------------+-------------------------------------------+
6 rows in set (0.001 sec)

8、开放远程连接,要有这个用户’root’@‘%’

# 开放端口,便于远程连接
[root@server ~]# firewall-cmd --permanent --add-port=3306/tcp
success
[root@server ~]# firewall-cmd --reload 
success

你可能感兴趣的:(MYSQL,mariadb)