MySQL自动化安装脚本
2016-01-03 12:18
656 查看
MySQL自动化安装脚本:mysql_auto_install.sh
使用方法:
使用方法:
#!/bin/bash arg1=$1 arg2=$2 arg3=$3 argsnum=$# user=mysql group=mysql current_release=`cat /etc/redhat-release` os_release1=5.9 os_release2=6.5 version=`echo $2| grep -o "[0-9].[0-9].[0-9][0-9]"` dir="p"$version"_project_"$3 mysqlpackages=( bison ncurses ncurses-devel gcc gcc-c++ make unzip openssl openssl-devel cmake libaio-devel ) pri_sql="delete from mysql.user where host != 'localhost' or user !='root';GRANT ALL PRIVILEGES ON *.* TO 'admin'@'%' IDENTIFIED BY PASSWORD '*7147F8A1B32468BDDDB4CB5AE0B2CC4FE4F4A17A' WITH GRANT OPTION;GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY PASSWORD '*7147F8A1B32468BDDDB4CB5AE0B2CC4FE4F4A17A' WITH GRANT OPTION;flush privileges;" logger(){ local info="$*" echo "[`date +'%Y/%m/%d %H:%M:%S'`] $info" } mkdirectories() { mkdir -pv /data/mysqldata/$dir/data/ mkdir -pv /data/mysqldata/$dir/tmp/ mkdir -pv /data/mysqldata/$dir/logs/binlog/ mkdir -pv /data/mysqldata/$dir/logs/relay-log/ mkdir -pv /data/mysqldata/$dir/etc chown mysql.mysql /data -R } function prepare(){ # check depended packages for MYSQL i=0 while [ $i -lt ${#mysqlpackages[@]} ] do str=`rpm -q ${mysqlpackages[$i]}| grep not` if [ -n "$str" ];then echo -e "Please install depended package \e[31m${mysqlpackages[$i]}\e[m for MYSQL first!" echo -e "Please execute: \e[31m yum install -y bison ncurses ncurses-devel gcc gcc-c++ make unzip openssl openssl-devel cmake libaio-devel \e[m" exit fi let i++ done } #check args function check_args() { if [ ! -z $arg1 ] && [ $arg1 == "-i" ] && [ ! -z $arg2 ] && [ ! -z $arg3 ] && [ $argsnum -eq 3 ];then sid=$arg2 else echo -e "\033[31mUsage:\033[0m ./`basename $0` -i pecona-5.5.33 3306 \033[31m OR \033[0m ./`basename $0` -i pecona-5.6.23 3306" exit fi if [ ! $arg2 == "pecona-5.6.23" ] && [ ! $arg2 == "pecona-5.5.33" ] ;then echo -e "mysql version must be \033[31m pecona-5.5.33 OR pecona-5.6.23 \033[0m" exit fi expr $arg3 + 0 &>/dev/null if [ $? -ne 0 ] ;then echo "port must be integer" exit elif [ $arg3 -le 3000 ]; then echo "port must be grater than 1024" exit elif [ $arg3 -gt 9999 ];then echo " port master be less than 9999" exit fi } function createuser() { #create group if not exists egrep "^$group" /etc/group >& /dev/null if [ $? -ne 0 ] then groupadd -g 550 $group fi #create user if not exists id $user >& /dev/null if [ $? -ne 0 ] then useradd -u 550 -g $group $user echo "mysql"|passwd mysql --stdin &> /dev/null fi } # install mysql server .... function install_mysql() { # if os is centos 5.9 ,then install 5.5.33 if [[ "$current_release" == *"$os_release1"* ]] && [[ "$sid" == "pecona-5.5.33" ]] ;then logger "start install_mysql" echo "pecona-5.5.33 on 5.9" logger "end install mysql" fi #if os is centos 5.9 ,then install 5.6.22 if [[ "$current_release" == *"$os_release1"* ]] && [[ "$sid" == "pecona-5.6.23" ]] ;then #wget http://xxxx/install/mysql/auto_install/mysql-5.5.33_5.9.tar.gz -P /tmp echo " pecona-5.6.23 on 5.9" fi #if os is centos 6.5,then install 5.5.33 if [[ "$current_release" == *"$os_release2"* ]] && [[ "$sid" == "pecona-5.5.33" ]] ;then #wget http://xxxx/install/mysql/auto_install/mysql-5.5.33_5.9.tar.gz -P /tmp echo " pecona-5.5.33 on 6.5" fi #if os is centos 6.5 ,then install 5.6.22 if [[ "$current_release" == *"$os_release2"* ]] && [[ "$sid" == "pecona-5.6.23" ]] ;then #wget http://xxxx/install/mysql/auto_install/mysql-5.5.33_5.9.tar.gz -P /tmp logger "start installing mysql" createuser mkdirectories tar xvf ./soft/percona-server-$version-$os_release2.tar.gz -C /usr/local &> /dev/null initdatabase logger "end installing mysql" fi } function initdatabase() { mv /usr/local/mysql/my.cnf /data/mysqldata/$dir/etc sedMycnf /usr/local/mysql/p$version/scripts/mysql_install_db --defaults-file=/data/mysqldata/$dir/etc/my.cnf --basedir=/usr/local/mysql/p$version/ --datadir=/data/mysqldata/$dir/data/ --user=mysql /usr/local/mysql/p$version/bin/mysqld_safe --defaults-file=/data/mysqldata/$dir/etc/my.cnf & } function sedMycnf() { sed -i "s/^port.*$/port=$arg3/g" /data/mysqldata/$dir/etc/my.cnf sed -i "s/p5.6.23_wms_3306/$dir/g" /data/mysqldata/$dir/etc/my.cnf } check_args prepare install_mysql >>mysql_install.log 2>&1
相关文章推荐
- MySQL中的integer 数据类型
- MySQL存储过程
- mysql中int、bigint、smallint 和 tinyint的区别与长度
- mysql load data 导出、导入 csv
- source命令执行SQL脚本文件
- MySQL创建用户及权限控制
- MySQL管理数据表
- linux下mysql添加用户
- mysql procedure
- mysql触发器
- MySQL 备份和恢复策略
- mac下安装mysql(转载)
- mysql 修改编码 Linux/Mac/Unix/通用(杜绝修改后无法启动的情况!)
- MySQL数据的导出、导入(mysql内部命令:mysqldump、mysql)
- mysql数据行转列
- Linux下修改MySQL编码的方法
- MySQL Server 日志
- MySQL 安全事宜
- MySQL 备份与恢复