小雪崩 发表于 2018-10-7 12:23:57

mysql5.6安装脚本

  #!/bin/bash
  # Notes: install mysql5.6 on ubuntu
  #
  mysql_install_dir=/home/ubuntu/data/mysql
  mysql_data_dir=/home/ubuntu/data/mysql/data
  mysql_6_version=5.6.28
  dbrootpwd=pass5871ABC
  Mem=`free -m | awk '/Mem:/{print $2}'`
  Swap=`free -m | awk '/Swap:/{print $2}'`
  Install_MySQL-5-6()
  {
  apt-getinstall cmake gcc-c++ cmake bison-devellibncurses5-dev libtcmalloc-minimal4
  #wget http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-${mysql_6_version}.tar.gz
  id -u mysql >/dev/null 2>&1
  [ $? -ne 0 ] && useradd -M -s /sbin/nologin mysql
  mkdir -p $mysql_data_dir;chown mysql.mysql -R $mysql_data_dir
  tar zxf mysql-${mysql_6_version}.tar.gz
  cd mysql-$mysql_6_version
  make clean
  [ ! -d "$mysql_install_dir" ] && mkdir -p $mysql_install_dir
  cmake . -DCMAKE_INSTALL_PREFIX=$mysql_install_dir \
  -DMYSQL_DATADIR=$mysql_data_dir \
  -DSYSCONFDIR=/etc \
  -DWITH_INNOBASE_STORAGE_ENGINE=1 \
  -DWITH_PARTITION_STORAGE_ENGINE=1 \
  -DWITH_FEDERATED_STORAGE_ENGINE=1 \
  -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
  -DWITH_MYISAM_STORAGE_ENGINE=1 \
  -DWITH_INNOBASE_STORAGE_ENGINE=1 \
  -DENABLED_LOCAL_INFILE=1 \
  -DENABLE_DTRACE=0 \
  -DEXTRA_CHARSETS=all \
  -DDEFAULT_CHARSET=utf8mb4 \
  -DDEFAULT_COLLATION=utf8mb4_general_ci \
  -DWITH_EMBEDDED_SERVER=1 \
  make -j `grep processor /proc/cpuinfo | wc -l`
  make install
  if [ -d "$mysql_install_dir/support-files" ];then
  echo "${CSUCCESS}MySQL install successfully! ${CEND}"
  cd ..
  rm -rf mysql-$mysql_6_version
  else
  rm -rf $mysql_install_dir
  echo "${CFAILURE}MySQL install failed, Please contact the author! ${CEND}"
  kill -9 $$
  fi
  /bin/cp $mysql_install_dir/support-files/mysql.server /etc/init.d/mysqld
  chmod +x /etc/init.d/mysqld
  update-rc.d mysqld defaults
  cd ..
  # my.cf
  [ -d "/etc/mysql" ] && /bin/mv /etc/mysql{,_bk}
  cat > /etc/my.cnf > /etc/profile
  [ -n "`grep ^'export PATH=' /etc/profile`" -a -z "`grep $mysql_install_dir /etc/profile`" ] && sed -i "s@^export PATH=\(.*\)@export PATH=$mysql_install_dir/bin:\1@" /etc/profile
  . /etc/profile

  $mysql_install_dir/bin/mysql -e "grant all privileges on *.* to root@'127.0.0.1'>
  $mysql_install_dir/bin/mysql -e "grant all privileges on *.* to root@'localhost'>
  $mysql_install_dir/bin/mysql -e "grant all privileges on *.* to root@'10.105.124.224'>  $mysql_install_dir/bin/mysql -uroot -p$dbrootpwd -e "delete from mysql.user where Password='';"
  $mysql_install_dir/bin/mysql -uroot -p$dbrootpwd -e "delete from mysql.db where User='';"
  $mysql_install_dir/bin/mysql -uroot -p$dbrootpwd -e "delete from mysql.proxies_priv where Host!='localhost';"
  $mysql_install_dir/bin/mysql -uroot -p$dbrootpwd -e "drop database test;"
  $mysql_install_dir/bin/mysql -uroot -p$dbrootpwd -e "reset master;"
  rm -rf /etc/ld.so.conf.d/{mysql,mariadb,percona}*.conf
  echo "$mysql_install_dir/lib" > mysql.conf
  ldconfig
  /etc/init.d/mysqld
  }
  Install_MySQL-5-6

页: [1]
查看完整版本: mysql5.6安装脚本