码迷,mamicode.com
首页 > 数据库 > 详细

shell安装MySQL二进制包

时间:2014-11-24 18:42:02      阅读:237      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   io   ar   color   sp   for   on   

现在解压MySQL二进制包,稍作配置,就能用了,安装速度快,安装来练习最好不过了,哈哈

该脚本只是安装二进制的MySQL包,my.cnf只修改了简单的选项,没有过多进行设置,若朋友们用我的脚本安装作为线上环境,需要在变量处修改为自己想要的内容即可,my.cnf你们要根据自己生产环境情况进行配置,安装包自己从官网下载,现在好像过墙才能下载了

官网:http://dev.mysql.com/downloads/mysql/

#!/bin/bash
#-------------------------------
#this install just for test ues
#write on 2014-11-24
#write by xuanzhi
#------------------------------

#定义变量
soft_path=/usr/local/src
mysql_pack=mysql-5.5.40-linux2.6-x86_64.tar.gz
mysql_version=`echo "mysql-5.5.40-linux2.6-x86_64.tar.gz"|cut -d - -f1,2`
mysql_user=mysql2
mysql_port=3308
mysql_passwd=123456
install_path=/usr/local
mysql_path=/usr/local/${mysql_version}
mysql_data_path=/data/${mysql_version}/data


#创建用户、赋权、安装
groupadd ${mysql_user}
if [ $? -ne 0 ]
then
  echo "this user ${mysql_user} is exist!!"
  exit 1
fi
useradd -r -g ${mysql_user} ${mysql_user}

cd ${soft_path}
if [ ! -e ${mysql_pack} ]
then
  echo "install pack is not exist!!"
  exit 1
fi
tar zxvf ${mysql_pack} -C ${install_path}
cd ${install_path} && mv ${mysql_version}-* ${mysql_version}
chown -R root:${mysql_user} ${mysql_path}
cd ${mysql_path} && cp support-files/my-large.cnf ${mysql_path}/my.cnf
mkdir -p /data/${mysql_version}
chown -R ${mysql_user}:${mysql_user} /data/${mysql_version}

#修改my.cnf
sed -i "/3306/{x;s/^/./;/^.\{2\}$/{x;s/3306/${mysql_port}/;b};x}" ${mysql_path}/my.cnf
sed -i "/socket/{x;s/^/./;/^.\{2\}$/{x;s#/tmp/mysql.sock#/data/${mysql_version}/mysql.sock#;b};x}" ${mysql_path}/my.cnf
sed -i "/${mysql_port}/a\datadir         = ${mysql_data_path}" ${mysql_path}/my.cnf
sed -i "/${mysql_port}/a\basedir         = ${mysql_path}" ${mysql_path}/my.cnf
sed -i "/${mysql_port}/a\use             = ${mysql_user}" ${mysql_path}/my.cnf
sed -i "/innodb_buffer_pool_size/s/^#//" ${mysql_path}/my.cnf

#初始化
cd ${mysql_path} 
yum install libaio -y
scripts/mysql_install_db --user=${mysql_user} --defaults-file=${mysql_path}/my.cnf

if [ $? -ne 0 ]
then
  echo -e "\e[1;31m[MySQL install init failure...]\e[0m"
  exit 1
fi

#添加启动关闭脚本
cat >>shutdown_mysql.sh<<EOF
#!/bin/bash

${mysql_path}/bin/mysqladmin --defaults-file=${mysql_path}/my.cnf -uroot -p${mysql_passwd} -S /data/${mysql_version}/mysql.sock shutdown
EOF

cat >>start_mysql.sh<<EOF
#! /bin/sh

nohup ${mysql_path}/bin/mysqld_safe --defaults-file=${mysql_path}/my.cnf >> ${mysql_path}/start_stop.log 2>&1 &
EOF

#启动MySQL
chmod +x shutdown_mysql.sh start_mysql.sh && sh start_mysql.sh
sleep 50
ps -aux |grep -v grep |grep ${mysql_port} &> /dev/null
if [ $? -ne 0 ]
then
   echo -e "\e[1;31m[MySQL start failure...]\e[0m"
   exit 1
else
    echo -e "\e[1;32m[MySQL start secessful]\e[0m"
fi
#修改密码
${mysql_path}/bin/mysqladmin -uroot password "${mysql_passwd}"  -S /data/${mysql_version}/mysql.sock 

若脚本有什么问题,希望大家能指出,让我知道更多自己的不足,谢谢^.^

shell安装MySQL二进制包

标签:style   blog   http   io   ar   color   sp   for   on   

原文地址:http://www.cnblogs.com/xuanzhi201111/p/4119065.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!