#!/bin/bash
#
#********************************************************************
#Author: Wuvikr
#QQ: 744123155
#Date: 2020-10-15
#FileName binary_install_mysql.sh
#URL: http://www.wuvikr.com
#Description The test script
#Copyright (C): 2020 All rights reserved
#********************************************************************
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
echo -e 'e[1;33m开始安装Mysql,请稍后...e[0m'
pwd1=/usr/local/
pwd2=$pwd1/mysql/
name=mysql-5.7.30-linux-glibc2.12-x86_64
[ -e ${name}.tar.gz ] && tar xf ${name}.tar.gz -C $pwd1 || { echo -e 'e[1;31m压缩包不存在,安装失败!e[0m';exit 3; }
install_mysql (){
# 在centos8上安装请解开下面的注释
#dnf -y install libaio ncurses-compat-libs &> /dev/null
id mysql &> /dev/null || { groupadd -r mysql;useradd -r -g mysql -s /sbin/nologin mysql;echo -e 'e[1;32mmysql用户创建成功成功!e[0m'; }
cd $pwd1
ln -s $name mysql
chown -R root.root $pwd2
cat > /etc/my.cnf <<EOF
[mysqld]
datadir=/data/mysql
skip_name_resolve=1
socket=/data/mysql/mysql.sock
log-error=/data/mysql/mysql.log
pid-file=/data/mysql/mysql.pid
[client]
socket=/data/mysql/mysql.sock
[mysql]
auto-rehash
prompt="\u@\h [\d]>"
EOF
ln -s ${pwd2}bin/* ${pwd1}bin/
mysqld --initialize --user=mysql --datadir=/data/mysql --basedir=/usr/local/mysql &> /dev/null && echo -e 'e[1;32m数据库初始化成功!e[0m'
cp ${pwd2}support-files/mysql.server /etc/init.d/mysqld
chkconfig --add mysqld
service mysqld start
echo -e 'e[1;32mMysql启动成功!e[0m'
PASS=`awk '/temporary password/{print $NF}' /data/mysql/mysql.log`
mysqladmin -uroot -p"$PASS" password 744123 &> /dev/null && echo -e 'e[1;32m您的初始密码修改成功,密码为: 744123 !e[0m'
}
install_mysql