#!/bin/bash
卸载自带 boost包
yum -y remove boost-* &> /dev/null
解包
read -p “请输入要安装的mysql包,以及绝对路径:” MQ PH
rpm -ivh
P
H
PH
PHMQ
cd ${PH}rpmbuild/SOURCES/
install bzip2
rpm -q bzip2
if [ $? -eq 0 ];then
echo “bzip2 is ready”
else
yum install -y bzip2 &> /dev/null
echo “bzip2安装成功”
fi
解压 boost包(可以搞个read)
cd ${PH}rpmbuild/SOURCES/
tar -jxvf boost_1_59_0.tar.bz2 -C /root/ &> /dev/null
删除本机自带的mysql相关文件
yum -y remove mysql* &> /dev/null
echo “删除已存在的mysql”
yum -y remove mariadb* &> /dev/null
echo “删除已存在的mariadb”
install mysql
安装mysql依赖包
yum install -y cmake make gcc gcc-c++ bison ncurses ncurses-devel &> /dev/null
添加mysql用户和用户组(可以改成交互式)
groupadd mysql
useradd -M -s /sbin/nologin -r -g mysql mysql
创建mysql数据库存放位置并修改目录权限(改成交互式,并运用上面交互结果)
mkdir -p /data/mysql/{data,log}
chown -R mysql:mysql /data/mysql
解压源码包 (可以吧cd改成函数)
cd ${PH}rpmbuild/SOURCES/
tar -zxvf mysql-5.7.26.tar.gz -C /root/
预编译
cd ${PH}mysql-5.7.26
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql
-DMYSQL_DATADIR=/data/mysql/data
-DSYSCONFDIR=/etc
-DWITH_MYISAM_STORAGE_ENGINE=1
-DWITH_INNOBASE_STORAGE_ENGINE=1
-DWITH_MEMORY_STORAGE_ENGINE=1
-DWITH_READLINE=1
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock
-DMYSQL_TCP_PORT=3306
-DENABLED_LOCAL_INFILE=1
-DWITH_PARTITION_STORAGE_ENGINE=1
-DEXTRA_CHARSETS=all
-DDEFAULT_CHARSET=utf8
-DDEFAULT_COLLATION=utf8_general_ci
-DDOWNLOAD_BOOST=1
-DWITH_BOOST=/root/boost_1_59_0
if [ $? -eq 0 ];then
echo -e “\033[32m 预编译成功\033[0m”
else
echo -e “\033[31m 预编译失败\033[0m”
exit 20
fi
编译 安装
make -j $( grep processor /proc/cpuinfo | wc -l)
if [ $? -eq 0 ];then
echo -e “\033[32m 编译成功\033[0m”
else
echo -e “\033[31m 编译失败\033[0m”
exit 21
fi
make install &> /dev/null
if [ $? -eq 0 ];then
echo -e “\033[32m 安装成功\033[0m”
else
echo -e “\033[31m 安装失败\033[0m”
exit 22
fi
改mysql目录权限
chown -R mysql:mysql /usr/local/mysql/
生成my.cnf配置文件
mv /etc/my.cnf{,.bak} &> /dev/null
echo “[mysqld]” >> /etc/my.cnf
echo “basedir=/usr/local/mysql” >> /etc/my.cnf
echo “datadir=/data/mysql/data” >> /etc/my.cnf
echo “port=3306” >> /etc/my.cnf
echo “socket=/usr/local/mysql/mysql.sock” >> /etc/my.cnf
echo “symbolic-links=0” >> /etc/my.cnf
echo “character-set-server=utf8” >> /etc/my.cnf
echo “log-error=/data/mysql/log/mysqld.log” >> /etc/my.cnf
echo “pid-file=/usr/local/mysql/mysqld.pid” >> /etc/my.cnf
生成服务启动脚本
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
加mysqld开机自启动
chkconfig --add mysqld
chkconfig mysqld on
2.2.16、 初始化数据库
/usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql
–basedir=/usr/local/mysql --datadir=/data/mysql/data
启动服务
/etc/init.d/mysqld start
添加环境变量
echo “export MYSQL_HOME=/usr/local/mysql” >> /etc/profile
echo “export PATH=
P
A
T
H
:
PATH:
PATH:MYSQL_HOME/bin” >> /etc/profile
source /etc/profile