centos6安装mysql8 shell脚本
下载mysql安装包:
wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.11-linux-glibc2.12-x86-64.tar.gz
解压并移动到/usr/local/mysql目录
tar zxvf mysql-8.0.11-linux-glibc2.12-x86_64.tar.gz
mv mysql-8.0.11-linux-glibc2.12-x86_64 /usr/local/mysql
执行脚本
sh -x MySQL8_Install.sh
脚本内容:
##################################################
#mysql_install.sh #
#initialize the Linux system to deploy lnmp #
#2018/10/31 16:41 #
#kangjie #
##################################################
#!/bin/sh
LOG_PATH=/home/initlog
LOG_FILE=$LOG_PATH/mysql_install.log
MYSQL_BASEDIR=/usr/local/mysql
MYSQL_DATA=/usr/local/mysql/data
MYSQL_POS=/home/pack
i=0
[ ! -d $LOG_PATH ] && mkdir -p $LOG_PATH
[ ! -d $MYSQL_BASEDIR ] && mkdir -p $MYSQL_BASEDIR
[ ! -d $MYSQL_DATA ] && mkdir -p ${MYSQL_DATA}
[ ! -d $MYSQL_POS ] && mkdir -p $MYSQL_POS
#mysql5.5.32
#check
function check(){
if [ $? != 0 ]
then
echo "\\\-Install $1 Failed!!!-///" >> $LOG_FILE
else
echo "--Install $1 Success--" >> $LOG_FILE
fi
}
#cmake
function prepare(){
yum install cmake gcc gcc-c++ gcc-g77 autoconf automake zlib* fiex* libxml* ncurses-devel libmcrypt* libtool-ltdl-devel* make -y
check libs
#useradd
groupadd mysql
useradd mysql -s /bin/nologin -M -g mysql
check groupadd-useradd
#mkdir
chown -R mysql.mysql /usr/local/mysql/data
check chown-mysql
}
#prepare success
#my.cnf
function mycnf(){
cat >>/etc/my.cnf<<EOF
[client]
port = 3306
socket = $MYSQL_DATA/mysql.sock
[mysqld]
port = 3306
socket = $MYSQL_DATA/mysql.sock
basedir = $MYSQL_BASEDIR
datadir = $MYSQL_DATA
skip-external-locking
key_buffer_size = 16M
max_allowed_packet = 20M
table_open_cache = 64
sort_buffer_size = 512K
net_buffer_length = 8K
read_buffer_size = 256K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M
skip-name-resolve
log-bin=mysql-bin
binlog_format=mixed
max_binlog_size = 500M
server-id = 1
[mysqld_safe]
log-error=$MYSQL_DATA/mysql.err
pid-file=$MYSQL_DATA/mysql.pid
[mysqldump]
quick
max_allowed_packet = 16M
[mysql]
no-auto-rehash
[myisamchk]
key_buffer_size = 20M
sort_buffer_size = 20M
read_buffer = 2M
write_buffer = 2M
[mysqlhotcopy]
interactive-timeout
EOF
}
#init
function init(){
$MYSQL_BASEDIR/bin/mysqld --initialize --basedir=$MYSQL_BASEDIR --datadir=$MYSQL_DATA --user=mysql
cp $MYSQL_BASEDIR/support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig mysqld on
}
#main
function main(){
prepare
mycnf
check mycnf
echo "export PATH=$MYSQL_BASEDIR/bin:$PATH" >> /etc/profile.d/mysql.sh
source /etc/profile
init
/etc/init.d/mysqld start
check mysql_start
}
main