源码安装mariadb

该文详细介绍了在CentOSStream8操作系统中安装MariaDB10.6.6的步骤,包括依赖包安装、软件包下载与解压、编译安装、数据库用户创建、配置文件修改、数据库初始化、安全配置以及设置环境变量等关键过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

实验拓扑

实验环境需要安装的软件
centos stream 8操作系统mariadb-10.6.6

实验步骤

1.安装依赖包
[root@localhost ~]# dnf -y install wget bison zlib-devel libcurl-devel boostdevel gcc gcc-c++ cmake ncurses-devel gnutls-devel libxml2-devel openssl-devel libevent-devel libaio-devel make
2.下载数据库软件包
[root@localhost ~]# ls
anaconda-ks.cfg Documents initial-setup-ks.cfg Music Public Videos
Desktop Downloads mariadb-10.6.6.tar.gz Pictures Templates
3.解压软件包
[root@localhost ~]# tar xf mariadb-10.6.6.tar.gz -C /usr/local/ //-C指定解压位置
4.进入解压包目录进行编译安装
[root@localhost ~]# cd /usr/local/
[root@localhost local]# ls
bin etc games include lib lib64 libexec mariadb-10.6.6 sbin share src
[root@localhost local]# cd mariadb-10.6.6/
[root@localhost mariadb-10.6.6]# cmake . -
DCMAKE_INSTALL_PREFIX=/usr/local/mariadb \ (定义数据库安装的位置)
-DMYSQL_DATADIR=/data/mariadb/ \ (定义数据存放的位置)
-DSYSCONFDIR=/usr/local/mariadb \ (数据库配置文件存放的位置)
-DMYSQL_USER=mysql -DMYSQL_TCP_PORT=3306 \ (指定数据库用户以及端口)
-DWITHOUT_TOKUDB=1 \ (开启功能)
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \ (指定数据库套接字文件)
-DDEFAULT_CHARSET=utf8 \ (定义支持的字符)
-DDEFAULT_COLLATION=utf8_general_ci
[root@localhost mariadb-10.6.6]# make && make install 安装
5.配置mairadb
[root@localhost mariadb-10.6.6]# useradd -r -s /sbin/nologin -d /data/mariadb
mysql //创建数据库用户
[root@localhost mariadb-10.6.6]# id mysql
uid=975(mysql) gid=974(mysql) groups=974(mysql)
[root@localhost mariadb]# cd support-files/
[root@localhost support-files]# ls
binary-configure magic mysqld_multi.server mysql-log-rotate mysql.server
policy wsrep.cnf wsrep_notify
[root@localhost support-files]# ll
total 40
-rwxr-xr-x. 1 root root 1155 Mar 1 22:30 binary-configure
6.修改数据库配置文件
[root@localhost ~]# cd /usr/local/mariadb //进入数据库安装位置
[root@localhost mariadb]# vi my.cnf //编辑数据库配置文件
[root@localhost mariadb]# cat my.cnf
[mysqld]
basedir=/usr/local/mariadb/ //数据库安装位置
datadir=/data/mariadb/ //数据存放位置
port=3306 //数据库端口号
pid-file=/data/mariadb/mysql.pid //数据库进程文件
socket=/tmp/mysql.sock //套接字文件位置
[mysqld_safe]
log-error=/data/mariadb/mysql.log //定义错误日志存放的位置
[client]
port=3306
socket=/tmp/mysql.sock
default-character-set=utf8 //定义支持的字符
7.初始化数据库
[root@localhost scripts]# /usr/local/mariadb/scripts/mariadb-install-db –
datadir=/data/maraidb //文件所在的绝对路径,datadir指定数据
存放位置
[root@localhost scripts]# chown -R root. /usr/local/mariadb
[root@localhost scripts]# chown -R mysql:mysql /data/mariadb/
8.开启数据库并且设置为开机自启
[root@localhost mariadb]# /etc/init.d/mysqld start //开启数据库服务
Reloading systemd: [ OK ]
Starting mysqld (via systemctl): [ OK ]
[root@localhost mariadb]# chkconfig --add mysqld //设置服务为开机自启
9.登录数据库查看是否启动成功
[root@localhost bin]# /usr/local/mariadb/bin/mysql -uroot //代表mysql
命令的绝对路径
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 4
Server version: 10.6.6-MariaDB Source distribution
Copyright © 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.对数据库进行安全配置
[root@localhost bin]# /usr/local/mariadb/bin/mysql_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):
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
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] y
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!
11.定义环境变量

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@localhost bin]# /usr/local/mariadb/bin/mysql -uroot -p123456
    Welcome to the MariaDB monitor. Commands end with ; or \g.
    Your MariaDB connection id is 15
    Server version: 10.6.6-MariaDB Source distribution
    Copyright © 2000, 2018, Oracle, MariaDB Corporation Ab and others.
    Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.
    MariaDB [(none)]>
    11.定义环境变量
    在这里插入图片描述
    [root@localhost ~]# which mysql
    /usr/bin/which: no mysql in
    (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin)
    [root@localhost ~]# source /etc/profile.d/mariadb.sh //让环境变量生效
    [root@localhost ~]# mysql -uroot -p123456 //验证
    Welcome to the MariaDB monitor. Commands end with ; or \g.
    Your MariaDB connection id is 15
    Server version: 10.6.6-MariaDB Source distribution
    Copyright © 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个

红包金额最低5元

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

抵扣说明:

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

余额充值