shell安装MySQL二进制包
现在解压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 "/\/data\/${mysql_version}\/mysql.sock/a\datadir = ${mysql_data_path}" ${mysql_path}/my.cnf
sed -i "/datadir/a\basedir = ${mysql_path}" ${mysql_path}/my.cnf
sed -i "/basedir/a\user = ${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
若脚本有什么问题,希望大家能指出,让我知道更多自己的不足,谢谢^.^
作者:陆炫志 出处:xuanzhi的博客 http://www.cnblogs.com/xuanzhi201111 您的支持是对博主最大的鼓励,感谢您的认真阅读。本文版权归作者所有,欢迎转载,但请保留该声明。 |