此脚本是Mysql安装脚本,有需要朋友可以参考,脚本内容如下:
系统环境:CentOS 7.9
软件版本:5.7.29
[root@localhost ~]# vim auto_install_mysql.sh
#!/bin/bash
#2020-3-12 10:31:01
#BY:YangXingZhen
#Auto Install MYSQL Server
source /etc/rc.d/init.d/functions
#Define MYSQL path variables
Boost_URL=https://mirrors.yangxingzhen.com/mysql
Boost_File=boost_1_59_0.tar.gz
#Define MYSQL path variables
MYSQL_URL=http://mirrors.163.com/mysql/Downloads/MySQL-5.7
MYSQL_FILES=mysql-5.7.29.tar.gz
MYSQL_FILES_DIR=mysql-5.7.29
MYSQL_PREFIX=/usr/local/mysql
MYSQL_DIR=/data/mysql
MYSQL_USER=mysql
#Install Package
yum -y install ncurses-devel perl perl-devel cmake wget gcc gcc-c++ bison* autoconf openssl-devel openssl
#Install Boost
wget -c ${Boost_URL}/${Boost_File}
tar zxf ${Boost_File} -C /usr/local/
#Install MYSQL
if [ ! -d ${MYSQL_PREFIX} ];then
wget -c ${MYSQL_URL}/${MYSQL_FILES}
tar zxf ${MYSQL_FILES}
cd ${MYSQL_FILES_DIR}
cmake . -DCMAKE_INSTALL_PREFIX=${MYSQL_PREFIX} \
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \
-DMYSQL_DATADIR=${MYSQL_DIR} \
-DSYSCONFDIR=/etc \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DDOWNLOAD_BOOST=1 \
-DWITH_BOOST=/usr/local/boost_1_59_0 \
-DENABLED_LOCAL_INFILE=1 \
-DMYSQL_TCP_PORT=3306 \
-DWITH_READLINE=1 \
-DMYSQL_USER=${MYSQL_USER} \
-DWITH_SSL=yes
if [ $? -eq 0 ];then
make && make install
action "The MYSQL Install Sussess..." /bin/true
else
action "The MYSQL Install Failed..." /bin/false
exit 1
fi
else
echo -e "\033[31mThe MYSQL already Install...\033[0m"
exit 1
fi
#Mysql config
useradd -s /sbin/nlogin mysql >/dev/null 2>&1
mkdir -p ${MYSQL_DIR}
chown -R ${MYSQL_USER}.${MYSQL_USER} ${MYSQL_DIR}
cat >/etc/my.cnf << EOF
[mysqld]
#数据存储目录
datadir = ${MYSQL_DIR}
#socket通信文件
socket = /tmp/mysql.sock
#使用mysql用户启动
user = ${MYSQL_USER}
#MYSQL服务运行的端口号
port = 3306
#开启bin-log日志
log-bin = mysql-bin
#MYSQL服务ID号
server-id = 1
#定义error错误文件
log-error = ${MYSQL_DIR}/mysqld.log
#PID文件路径
pid-file = mysqld.pid
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
#设置字符集为utf8
character-set-server = utf8
[client]
default-character-set = utf8
port = 3306
socket = /tmp/mysql.sock
[mysql]
default-character-set = utf8
EOF
#Initialization Mysql
/usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/data/mysql/ --basedir=/usr/local/mysql
ln -sf ${MYSQL_PREFIX}/bin/* /usr/bin
\cp ${MYSQL_PREFIX}/support-files/mysql.server /etc/init.d/mysqld
chmod o+x /etc/init.d/mysqld
/etc/init.d/mysqld start
脚本执行方式:
[root@localhost ~]# sh auto_install_mysql.sh
若文章图片、下载链接等信息出错,请在评论区留言反馈,博主将第一时间更新!如本文“对您有用”,欢迎随意打赏,谢谢!
继续阅读
Wechat
微信扫一扫,加我!
微信号已复制
微信公众号
微信扫一扫,关注我!
公众号已复制
评论