CentOS7 编译安装MariaDB

本文详细介绍了在CentOS7系统上编译安装MariaDB的全过程,包括查看和删除数据库配置文件、卸载自带mariadb-libs、安装依赖、创建用户和组、下载源码、编译安装、设置开机启动、添加环境变量、连接测试以及初始化数据库等步骤。如果在编译过程中遇到内存不足的问题,文章也给出了相应的解决建议。

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

1、查看数据库配置文件

[root@i****z ~]# find -H /etc/ | grep my.c
/etc/pki/tls/certs/make-dummy-cert
/etc/pki/tls/certs/renew-dummy-cert
/etc/my.cnf
/etc/my.cnf.d
/etc/my.cnf.d/mysql-clients.cnf

2、删除数据库配置文件

[root@i****z ~]# rm -rf /etc/my.cnf /etc/my.cnf.d/
[root@i****z ~]# 

 3、查找、卸载系统自带mariadb-libs

[root@i****z ~]# rpm -qa|grep mariadb-libs
mariadb-libs-5.5.52-1.el7.x86_64

[root@i****z ~]# rpm -e mariadb-libs-5.5.52-1.el7.x86_64 --nodeps
warning: file /etc/my.cnf.d/mysql-clients.cnf: remove failed: No such file or directory
warning: file /etc/my.cnf.d: remove failed: No such file or directory
warning: file /etc/my.cnf: remove failed: No such file or directory

4、安装相关依赖包

[root@i****z ~]# yum -y install libaio libaio-devel bison bison-devel zlib-devel
[root@i****z ~]# yum -y install openssl openssl-devel ncurses ncurses-devel libcurl-devel libarchive-devel
[root@i****z ~]# yum -y install boost boost-devel cmake cmake-devel

5、创建用户和组

[root@i****z ~]# groupadd -r mysql
[root@i****z ~]# useradd -g mysql -s /sbin/nologin mysql

6、创建安装目录和数据目录,MariaDB官网下载https://downloads.mariadb.org/

[root@i****z ~]# mkdir /usr/local/mysql

[root@i****z ~]# mkdir -p /data/mysql
# 下面一句表示创建数据库,在安装完成后,初始化数据库的时候会自动加载data、bin_log等库,可以不使用
[root@i****z ~]# mkdir -pv /data/mysql/{data,bin_log,run,log,tmp}

[root@i****z ~]# chown -R mysql:mysql /usr/local/mysql/
[root@i****z ~]# chown -R mysql:mysql /data/mysql/
[root@i****z ~]# cd /usr/local/mysql/
[root@i****z mysql]# wget -O mariadb-10.3.9.tar.gz https://downloads.mariadb.org/interstitial/mariadb-10.3.9/source/mariadb-10.3.9.tar.gz/from/http%3A//mirrors.neusoft.edu.cn/mariadb/?serve
[root@i****z mysql]# tar -zxvf mariadb-10.3.9.tar.gz 
[root@i****z mysql]# cd mariadb-10.3.9 

7、创建编译文件并编译(如果在编译过程中提示内存不足,请查看文章末尾内容)

[root@i****z mariadb-10.3.9]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/data/mysql \
-DSYSCONFDIR=/etc \
-DWITHOUT_TOKUDB=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STPRAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWIYH_READLINE=1 \
-DWIYH_SSL=system \
-DVITH_ZLIB=system \
-DWITH_LIBWRAP=0 \
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \
-DDEFAULT_CHARSET=utf8mb4 \
-DDEFAULT_COLLATION=utf8mb4_unicode_ci

# 说明
# -DCMAKE_INSTALL_PREFIX=/usr/local/mysql    安装根目录
# -DMYSQL_DATADIR=/data/mysql                数据存储目录
# -DSYSCONFDIR=/etc                          配置文件存放目录
# -DMYSQL_UNIX_ADDR=/tmp/mysql.sock          临时文件存放目录
# -DWITHOUT_TOKUDB=1                         tokudb引擎不支持
# -DWITH_INNOBASE_STORAGE_ENGINE=1           innoDB引擎支持
# -DWITH_ARCHIVE_STPRAGE_ENGINE=1            archive引擎支持
# -DWITH_BLACKHOLE_STORAGE_ENGINE=1          blackhole引擎支持
# -DWIYH_READLINE=1                          readline库
# -DWIYH_SSL=system                          使用系统自带的ssl库
# -DVITH_ZLIB=system                         使用系统自带的zlib库
# -DWITH_LIBWRAP=0                           禁用libwrap库
# -DDEFAULT_CHARSET=utf8mb4                  默认字符集
# -DDEFAULT_COLLATION=utf8mb4_unicode_ci     默认字符集校对

[root@i****z mariadb-10.3.9]# make && make install
# 编译过程有点漫长......

# 如果报以下错误,说明内存小,编译失败(安装MySQL遇到过)
c++: internal compiler error: Killed (program cc1plus)
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://bugzilla.redhat.com/bugzilla> for instructions.
make[2]: *** [sql/CMakeFiles/sql_gis.dir/gis/crosses.cc.o] Error 4
make[1]: *** [sql/CMakeFiles/sql_gis.dir/all] Error 2
make: *** [all] Error 2

8、切换至安装目录,执行生成数据库操作,添加开机启动,添加系统服务

[root@i****z mariadb-10.3.9]# cd /usr/local/mysql/
[root@i****z mysql]# scripts/mysql_install_db --datadir=/data/mysql --user=mysql
[root@i****z mysql]# cp support-files/mysql.server /etc/init.d/mysqld 
[root@i****z mariadb-10.3.9]# cd /etc/init.d/
[root@i****z init.d]# chkconfig --add mysqld
[root@i****z init.d]# chkconfig mysqld on

9、添加环境变量

[root@i****z mysql]# vim /etc/profile.d/mysql.sh
# 输入内容:
export PATH=$PATH:/usr/local/mysql/bin/

[root@i****z mysql]# chmod 777 /etc/profile.d/mysql.sh 
[root@i****z mysql]# source /etc/profile.d/mysql.sh 

10、连接测试

[root@i****z mysql]# mysql -u -p
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 10
Server version: 10.3.9-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 |
| test               |
+--------------------+
2 rows in set (0.000 sec)

MariaDB [(none)]> exit
Bye
[root@i****z mysql]# 

11、初始化mariadb

[root@i****z mysql]# /usr/local/mysql/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
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none): 
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

# 设置root密码
Set root password? [Y/n] y
New password: 
Re-enter new password: 
Sorry, passwords do not match.

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 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值