MySQL安装:二进制在线安装脚本(5.6版本)
一.脚本
> #!/bin/bash
> . /etc/init.d/functions
> DIR=`pwd`
> MYSQL_VERSION=5.6.51
> NAME="mysql-${MYSQL_VERSION}-linux-glibc2.12-x86_64.tar.gz"
> FULL_NAME=${DIR}/${NAME}
> URL=http://mirrors.163.com/mysql/Downloads/MySQL-5.6
> DATA_DIR="/data/mysql"
> rpm -q wget || yum -y -q install wget
> wget $URL/$NAME || { action "下载失败,异常退出" false;exit 10; }
> yum install -y -q libaio perl-Data-Dumper autoconf
> if [ -f ${FULL_NAME} ];then
> action "安装文件存在"
> else
> action "安装文件不存在" false
> exit 3
> fi
> if [ -e /usr/local/mysql ];then
> action "Mysql 已经安装" false
> exit 3
> else
> tar xf ${FULL_NAME} -C /usr/local/src
> ln -sv /usr/local/src/mysql-${MYSQL_VERSION}-linux-glibc2.12-x86_64 /usr/local/mysql
> if id mysql;then
> ? action "mysql 用户已经存在,跳过创建用户过程"
> else
> ? useradd -r -s /sbin/nologin mysql
> fi
>
> if id mysql;then
> ? chown -R mysql.mysql /usr/local/mysql/*
> ? if [ ! -d /data/mysql ];then
> ? mkdir -pv /data/mysql && chown -R mysql.mysql /data
> ? /usr/local/mysql/scripts/mysql_install_db --user=mysql --datadir=/data/mysql --basedir=/usr/local/mysql/
> ? cp /usr/local/src/mysql-${MYSQL_VERSION}-linux-glibc2.12-x86_64/support-files/mysql.server /etc/init.d/mysqld
> ? chmod a+x /etc/init.d/mysqld
> ? cat > /etc/my.cnf <<-‘EOF‘
> [mysqld]
> ? socket=/data/mysql/mysql.sock
> ? user=mysql
> symbolic-links=0
> datadir=/data/mysql
> innodb_file_per_table=1
> [client]
> port=3306
> socket=/data/mysql/mysql.sock
> [mysqld_safe]
> log-error=/var/log/mysqld.log
> pid-file=/tmp/mysql.sock
> EOF
> ? ln -sv /usr/local/mysql/bin/mysql /usr/bin/mysql
> ? /etc/init.d/mysqld start
> ? chkconfig --add mysqld
> ? else
> ? action "MySQL数据目录已经存在" false
>? exit 3
> ? fi
> fi
> fi
二.注
脚本出自Mr.wang,已在CentOS7环境中测试,放心使用.
请严格按照代码编辑格式进行缩进,不要无脑复制