二进制安装mysql脚本_二进制安装mysql的shell脚本

配合文档看,挺简单的。

#!/bin/bash

###2016-3-23

###version 1.0

####tishi yonghu

cat<< AA

you must mv the mysql_package to /root/tools/ .

AA

sleep 2

###define var

tools_dir="/root/tools"

package_name="`cd $tools_dir && ls mysql-*-linux*`"

version_num="`cd $tools_dir && ls mysql*linux* -d | awk -F"-" ‘{print $2}‘`"

install_path="/application/mysql$version_num"

####test if have a mysql user

id mysql &>/dev/null

[ $? -ne 0 ] && useradd mysql -s /sbin/login -M && echo "mysql_user ok." || echo "mysql_user ok."

###test if have a install dir.

[ ! -d $install_path ] && mkdir -p $install_path && echo "install_dir ok." || ( echo "$install_path is exsit.";exit 1 )

###tar and mv mysql_package

cd $tools_dir && tar xf $package_name

dir_name="`ls mysql*x86_64 -d`"

mv ${dir_name}/* $install_path && sleep 7 && rm -rf ${dir_name} && echo "tar and mv ok." ||  exit 1

###ln dir and dir

ln -s ${install_path}/ /application/mysql  && echo "ln dir ok." || exit 1

###chown dir

chown -R mysql.mysql /application/mysql/ && echo "chwon dir ok." || exit 1

###init mysql

/application/mysql/scripts/mysql_install_db --basedir=/application/mysql/ --datadir=/application/mysql/data/ --user=mysql &>/dev/null

[ $? -eq 0 ] && echo "init ok." || exit 1

###cp my-cnf

[ -f /etc/my.cnf ] && mv /etc/my.cnf /etc/my.cnf.bak

cp /application/mysql/support-files/my-innodb-heavy-4G.cnf /etc/my.cnf

[ $? -eq 0 ] && echo "cp my.cnf ok." || exit 1

###mysql

cp /application/mysql/bin/mysqld_safe /application/mysql/bin/mysqld_safe.bak

[ $? -ne 0 ] && exit 1

sed -i ‘s#/usr/local/mysql#/application/mysql#g‘ /application/mysql/bin/mysqld_safe

[ $? -ne 0 ] && exit 1

grep ‘PATH="/application/mysql/bin:$PATH"‘ /etc/profile &>/dev/null

[ $? -ne 0 ] && echo ‘PATH="/application/mysql/bin:$PATH"‘ >> /etc/profile && source /etc/profile || echo "path ok."

[ $? -ne 0 ] && exit 1

#/application/mysql/bin/mysqld_safe & >/dev/null 2>&1

#[ $? -ne 0 ] && exit 1

cp /application/mysql/support-files/mysql.server /etc/init.d/mysqld

[ $? -ne 0 ] && exit 1

sed -i ‘s#/usr/local/mysql#/application/mysql#g‘ /etc/init.d/mysqld

[ $? -ne 0 ] && exit 1

chmod +x /etc/init.d/mysqld

[ $? -ne 0 ] && exit 1

chkconfig --add mysqld

[ $? -ne 0 ] && exit 1

grep ‘/etc/init.d/mysqld start‘ /etc/rc.local &>/dev/null

[ $? -ne 0 ] && echo ‘/etc/init.d/mysqld start‘ >> /etc/rc.local

[ $? -ne 0 ] && exit 1

#/application/mysql/bin/mysqladmin -uroot password "123456"

#[ $? -ne 0 ] && exit 1

#/application/mysql/binmysql -uroot -p123456

#[ $? -ne 0 ] && exit 1

############done

echo "now you can use mysql,thanks for your wait."

原文:http://10546390.blog.51cto.com/10536390/1754258

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值