Automated Installation MySQL-5.6.27

Source: Internet
Author: User

#!/bin/bashmysql_major_version= "5.6" mysql_minin_version= "Mysql_download_url=" http://mirrors.sohu.com/mysql/ Mysql-${mysql_major_version}/mysql-${mysql_major_version}.${mysql_minin_version}.tar.gz "Tools_download_dir="/ Home/tools "mysql_install_dir="/app/mysql "mysql_root_dir="/mydata "mysql_data_dir=" ${Mysql_root_dir}/data "Mysql_ Bin_log_dir= "${mysql_root_dir}/bin_log" mysql_error_log_dir= "${mysql_root_dir}/error_log" Mysql_relay_log_dir= "$ {mysql_root_dir}/relay_log "mysql_user=" MySQL "mysql_group=" MySQL "mysql_cmake=" Cmake . -dcmake_install _prefix=${mysql_install_dir}  -dmysql_datadir=${mysql_data_dir}  -dmysql_unix_addr=${mysql _root_dir}/mysql.sock  -ddefault_charset=utf8  -ddefault_collation=utf8_general_ci   -dextra_charsets=all  -denabled_local_infile=on  -dwith_innobase_storage_engine=1   -dwith_federated_storage_engine=1  -dwith_blackhole_storage_engine=1  - Dwithout_example_storage_engine=1  -dwith_fast_mutexes=1  -denabled_local_infile=1 -dwith_readline=1 - Dwith_embedded_server=1 -dwith_debug=0 "path=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/ sbinexport path#***************************************************************************************** Check_result () {   if [ $1 != 0 ];then    echo -e   "\e[1;31m  ERROR!!!!  <========exit  install  mysql=======>   \e[0m "     exit 1   fi}#***************************************************************** Root_ Or_not ()  {if [  "$UID"  != 0 ];then  echo -e  "\e[1;31m   error,  you are not root ,please login in root to execule the  scripts!  \e[0m "  exit 1else  echo -e  " \e[1;31m good,  you are root,and you can continue to install mysql! \e[0m " fi}#*********************************************************************************************************** install_or_not  ()  {  read  -p  "Installed mysql,press n to exit or  press y to  continue:  " INSTALL_Y_N  case  $INSTALL _y_n in  y|y)              echo -e  "\e[1;31m <========= starting install  mysql=======>  \e[0m "              start_install  ;;   n|n)             echo -e    "\e[1;31m <=========stop install  mysql=======>  \e[0m"               exit 0  ;;   *)               install_or_ not  ;;   esac}#******************************************************************************************** Check_user_group ()  {   echo  "\e[1;44m <======creating  mysql  user and group == ====>  \e[0m "   check_user= ' awk -f:  ' {a[$1]}end{ if (" ' $Mysql _user ' ")  in a) {print  "yes"} else print  "no"} ' &NBSP;&NBSP;/ETC/PASSWd '   check_group= ' awk -f:  ' {a[$1]}end{ if ("' $Mysql _group '"  in a) {print  "Yes"} else print  "no"} '   /etc/group '   if  [  ' ${check_user} '   =  "yes"  -a   "${check_group}"  =  "Yes"  ]; then       echo -e  "\e[1;31m mysql  is  exists! \e[0m"   else      /usr/sbin/groupadd  mysql  &&   /usr/sbin/useradd -g mysql -m mysql   fi}#********************* *************************************************************************************************************** Download_mysql ()  {  echo -e  "\e[1;44m  Starting download mysql source tarball,version is ${mysql_major_version}.${mysql _minin_version},download url:http://mirrors.sohu.com \e[0m "  [ ! -d ${tools_download_dir}  ] &&  mkdir ${tools_download_dir}  -p  cd ${tools_ download_dir}    yum  install   wget  -y   Check_result $?  wget ${mysql_download_url}  check_result $?} #************************************************************************************************************** Install_process ()  {yum -y install  gcc gcc-c++  ncurses-devel bison  perl check_result $?echo  -e  "\e[1;44m mysql source tarball,create mysql  data_root directory   ${mysql_root_dir} \e[0m "[ ! -d ${mysql_data_dir} ]       &&  mkdir  ${mysql_data_dir}  -p[ ! -d ${mysql_bin_log_dir} ]    && mkdir ${mysql_bin_log_dir}   -p[ ! -d ${mysql_error_ log_dir} ] && mkdir ${mysql_error_log_dir}  -p[ ! -d ${ mysql_relay_log_dir} ] && mkdir ${mysql_relay_log_dir}echo -e  "\e[1;44m   creating${mysql_install_dir} \e[0m "[ ! -d ${mysql_install_dir} ]  && mkdir -p ${Mysql_install_dir}echo -e  "\e[1;44m <======first, download cmake =====> \e[0m "cd ${tools_download_dir}  wget https:// Cmake.org/files/v3.4/cmake-3.4.0.tar.gzcheck_result $?if [ ! -f ${tools_download_dir} /cmake-3.4.0.tar.gz ]  ;then  echo  "\e[1;31m  cmake-3.4.0.tar.gz  is not exist!!  \e[0m "  exit 1fitar xf cmake-3.4.0.tar.gzcheck_result $?cd  cmake-3.4.0 ./configure  check_result $?gmakecheck_result $?     gmake   installcheck_result $? echo   -e   "\e[1;44m  cmake  development tool is  installed ,sencond:  starting install   mysql-${mysql_major_version}.${mysql_minin_version}.tar.gz \e[0m "If [ ! -f ${tools_ download_dir}/mysql-${mysql_major_version}.${mysql_minin_version}.tar.gz ] ; then   echo  "\e[1;31m  mysql-${mysql_major_version}.${mysql_minin_version}.tar.gz is not  exist!!  \e[0m "  exit 1ficd  ${Tools_download_dir}   tar xf   mysql-${Mysql_Major_version}.${Mysql_Minin_version}.tar.gz   check_result $?cd   mysql-${mysql_major_version}.${mysql_minin_version} $Mysql _cmakecheck_result $?make    check _result $?make  installcheck_result $?} Configure_env () {echo -e   "\e[1;44m  <==========configure system  environment========>   \e[0m "/bin/cat  /etc/profile  | grep  mysql  &&  result=echo $?  if [  "$result"  != 0  ];then  echo  "Export path=${mysql_install_dir}/bin:\ $PATH"    >>  /etc/profile  &&  source  /etc/profile  echo   -e  "\e[1;31m  <=======environment is ok.======>  \e[0m" else   echo -e  "\e[1;31m  <=======environment is ok,please don ' t  repeat configure it.======>  \e[0m "&NBSP;FI}CONFIGURE_PRIvilege () {  /bin/chown  -r  ${mysql_user}.${mysql_group}   ${ Mysql_root_dir}  check_result $?  /bin/chmod  -r  1777 /tmp    }mysql_init () {  cd ${mysql_install_dir}/scripts  ./mysql_install_db  --basedir=${mysql_install_dir}  --datadir=${mysql_data_dir}  --user=${mysql_user}   check_result $?} Prepare_start_shell () {  cd  ${mysql_install_dir}/support-files  check_result  $?  /bin/cp  mysql.server  /etc/init.d/mysqld  check_result  $?} configure_conf () {echo -e  "\e[1;44m confiugre my.cnf file \e[0m"/bin/cat    >/etc/my.cnf  << eof[mysqld]datadir=/mydata/datasocket=/mydata/ Mysql.sockuser=mysqlsymbolic-links=0[mysqld_safe]log-error=/mydata/error_log/mysqld.logpid-file=/var/run/mysqld/mysqld.pideofecho -e   "configure file finished"}start_mysql () {  /etc/ Init.d/mysqld start   check_result $?} #************************************************************************************************************** Start_install ()  {  check_user_group   download_mysql  install_process  configure_env  configure_privilege   mysql_init  prepare_start_shell  configure_conf  start_mysql}#****** *************************************************************************************************************** Root_or_notinstall_or_not

This article from the "Do not ask for the best, only better" blog, please be sure to keep this source http://yujianglei.blog.51cto.com/7215578/1725585

Automated Installation MySQL-5.6.27

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.