二進位安裝mysql的shell指令碼

來源:互聯網
上載者:User

標籤:shell mysql

配合文檔看,挺簡單的。

#!/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." 


本文出自 “10536390” 部落格,請務必保留此出處http://10546390.blog.51cto.com/10536390/1754258

二進位安裝mysql的shell指令碼

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.