源码编译安装MariaDB
【摘要】 安装数据库的几种方式三
=================================
/*
* @系统:CentOS7.9
* @描述:数据库安装的几种方法三
*/
=================================
一、环境准备
1. 安装基础包和依赖包
# yum install -y bison bison-devel zlib-devel libcurl-devel libarchive-devel boost-devel gcc gcc-c++ cmake ncurses-devel gnutls-devel libxml2-devel openssl-devel libevent-devel libaio-devel
2. 获取源码包
https://downloads.mariadb.org/interstitial/mariadb-10.4.13/source/mariadb-10.4.13.tar.gz/from/http%3A//mirrors.tuna.tsinghua.edu.cn/mariadb/
3. 上传文件到服务器
# cd /usr/local/src/
# rz
4. 检查是否安装数据库(有则卸载)
# rpm -qa|grep mariadb
mariadb-libs-5.5.65-1.el7.x86_64
# rpm -qa|grep mysql
5. 解压
# tar -zxvf mariadb-10.4.13.tar.gz
6. 创建用户
# useradd -r -d /data/mysqldb -s /sbin/nologin mysql
7. 创建数据库存放文件夹并授权
# mkdir -pv /data/mysqldb #创建文件夹
mkdir: created directory ‘/data’
mkdir: created directory ‘/data/mysqldb’
# chown -R mysql.mysql /data/mysqldb #属组
# chmod 770 /data/mysqldb #执行权限
二、安装
1. 编译
# cd mariadb-10.4.13
# 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/loacl/mysql/mysql.sock \
-DDEFAULT_CHARSET=utf8mb4 \
-DDEFAULT_COLLATION=utf8mb4_general_ci
2. 安装
# make && make install
三、配置
1. 添加环境变量
# echo PATH:/usr/local/mysql/bin:$PATH > /etc/profile.d/mysql.sh
# . /etc/profile.d/mysql.sh #使其生效
-bash: PATH:/usr/local/mysql/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin: No such file or directory
2. 生成数据库
# cd /usr/local/mysql/
# scripts/mysql_install_db --datadir=/data/mysqldb/ --user=mysql --basedir=/usr/local/mysql
3. 修改数据库配置文件
# cd /etc/
# vim my.cnf
=================================
[mysqld]
datadir=/data/mysqldb
socket=/usr/local/mysql/mysql.sock
[client]
port=3306
socket=/usr/local/mysql/mysql.sock
4. 启动脚本
# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
5.添加环境变量
# echo PATH=/usr/local/mysql/bin:$PATH > /etc/profile.d/mysql.sh
# . /etc/profile.d/mysql.sh
# echo $PATH
/usr/local/mysql/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
6. 开机启动
# chkconfig --add mysqld
# chkconfig --list
Note: This output shows SysV services only and does not include native
systemd services. SysV configuration data might be overridden by native
systemd configuration.
If you want to list systemd services use 'systemctl list-unit-files'.
To see services enabled on particular target use
'systemctl list-dependencies [target]'.
mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off
netconsole 0:off 1:off 2:off 3:off 4:off 5:off 6:off
network 0:off 1:off 2:on 3:on 4:on 5:on 6:off
7. 设置权限
# setfacl -R -m u:mysql:rwx /usr/local/mysql/
8. 启动服务
# systemctl start mysqld
9. 初始化(略)
-本篇完-
【版权声明】本文为华为云社区用户原创内容,转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息, 否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)