#!/bin/bash
#version 2018-04-01 by san
setenforce 0
yum install wget -y
sourceDir=$(pwd)
installDir=/usr/local
mysqlData=/data1/mysqldb
mysqlBaseDir=/usr/local/mysql
mysqldb="mysql-5.7.21-linux-glibc2.12-x86_64.tar.gz"
xtrabackup="percona-xtrabackup-24-2.4.8-1.el7.x86_64.rpm"
check_mariadb(){
if [ $(rpm -qa|grep mariadb|wc -l) -gt 1 ]
then
echo "Find mariadb installed!"
read -t 6 -p "default y|Y remove pause 6 seconds!n|N Cacle install!" yesNo
if [[ $yesNo == "n" || $yesNo == "N" ]]
then
echo "Cacle install mysqldb" && exit 0
else
yum -y remove mariadb mariadb-server
rm -rf /etc/my.cnf
fi
fi
}
check_mariadb
[ -f $sourceDir ]||mkdir $sourceDir -pv
[[ $(id mysql >/dev/null && echo $?) == 0 ]] && echo "mysql is exsits!" || useradd -r mysql
cd $sourceDir
[ -f ${sourceDir}/${mysqldb} ] || wget https://cdn.mysql.com/Downloads/MySQL-5.7/mysql-5.7.21-linux-glibc2.12-x86_64.tar.gz
tar -xvf $mysqldb -C $installDir
cd $installDir
ln -sv mysql-5.7.21-linux-glibc2.12-x86_64 mysql
[ -f /etc/profile.d/mysql.sh ]|| echo "export PATH=$mysqlBaseDir/bin:$PATH" >/etc/profile.d/mysql.sh
source /etc/profile.d/mysql.sh
#创建mysql数据目录
[ -d $mysqlData ]|| mkdir -pv $mysqlData
chown mysql.mysql $mysqlData
$mysqlBaseDir/bin/mysqld --initialize-insecure --datadir=$mysqlData --user=mysql --basedir=$mysqlBaseDir/
[ -d $mysqlBaseDir/etc/my.cnf.d ] || mkdir -pv $mysqlBaseDir/etc/my.cnf.d
[ -d $mysqlBaseDir/log ] || mkdir -pv $mysqlBaseDir/log
echo '
[mysqld]
datadir=/data1/mysqldb
socket=/data1/mysqldb/mysql.sock
key_buffer_size = 16M
max_allowed_packet = 16M
thread_stack = 192K
thread_cache_size = 8
query_cache_limit = 1M
query_cache_size = 64M
query_cache_type = 1
symbolic-links=0
#binlog
server-id = 1
log_bin = /data1/mysqldb/mysql-bin.log
#建议打开
innodb_file_per_table=ON
skip_name_resolve=ON
[mysqld_safe]
log-error=/usr/local/mysql/log/error.log
pid-file=/var/run/mysql/mysql.pid
!includedir /usr/local/mysql/etc/my.cnf.d
' >/$mysqlBaseDir/etc/my.cnf
touch /usr/local/mysql/log/error.log
chown mysql.mysql $mysqlBaseDir/* -R
chown mysql.mysql /usr/local/mysql/etc/my.cnf.d -R
#add manager script
cp -rp $mysqlBaseDir/support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig mysqld on
systemctl daemon-reload
service mysqld start
ln -sv /data1/mysqldb/mysql.sock /tmp/mysql.sock
###
echo "mysql root password is empty"
echo 'install xtrabackup tool'
cd $sourceDir
[ -f ${sourceDir}/${xtrabackup} ] || wget https://www.percona.com/downloads/XtraBackup/Percona-XtraBackup-2.4.8/binary/RedHat/7/x86_64/percona-xtrabackup-24-2.4.8-1.el7.x86_64.rpm
yum install ./percona-xtrabackup-24-2.4.8-1.el7.x86_64.rpm -y
CentOS6.x/CentOS7.x一键安装MySQL5.6/5.7并定制数据目录(3)
内容版权声明:除非注明,否则皆为本站原创文章。
转载注明出处:https://www.heiqu.com/46f022b93e10d70f7450ed6ca08a8c43.html