mariadb编译安装脚本
作者:互联网
脚本
#!/bin/bash
OK_COLOR="echo -e \e[1;32m"
ERR_COLOR="echo -e \e[1;35m"
END="\e[0m"
MARIADB="mariadb-10.2.31"
#安装依赖包
for package in \
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 wget;
do
# rpm -q $package > /dev/null && ${OK_COLOR}${package}:已安装$END || \
# { sleep 2; ${ERR_COLOR}开始安装:$package${END}; yum -y install $package > /dev/null;}
if rpm -q $package > /dev/null;then
${OK_COLOR}${package}:已安装$END
else
${ERR_COLOR}开始安装:$package${END}
sleep 2
yum -y install $package > /dev/null && ${ERR_COLOR}安装成功:$package${END} || exit 1
fi
done
#创建用户、数据库目录、更改权限、解压源码包
useradd -r -s /sbin/nologin -d /data/mysql mysql > /dev/null
mkdir -p /data/mysql > /dev/null
chown mysql.mysql /data/mysql
cd /root/
tar xvf /root/${MARIADB}.tar.gz -C /usr/local/src
#编译安装
#安装目录、数据库目录、配置文件目录、用户、引擎、字符集、排序等设置
cd /usr/local/src/$MARIADB
cmake . \
-DCMAKE_INSTALL_PREFIX=/apps/mysql \
-DMYSQL_DATADIR=/data/mysql/ \
-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=/data/mysql/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci
make && make install
#设置环境变量
echo 'PATH=/apps/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
export $PATH
#生成数据库文件
cd /apps/mysql
scripts/mysql_install_db --datadir=/data/mysql --user=mysql
#拷贝配置文件、设置启动脚本并启动
cp /apps/mysql/support-files/my-huge.cnf /etc/my.cnf
cp /apps/mysql/support-files/mysql.server /etc/init.d/mysqld
chkconfig --add mysql
service mysqld start
查看检验
[root@test7 ~]# mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 11
Server version: 10.2.31-MariaDB-log 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)]>
标签:脚本,END,package,COLOR,devel,编译,mysql,DWITH,mariadb 来源: https://www.cnblogs.com/windman0/p/14347840.html