mysql-5.7.20 Binary Installation | Backup recovery

Source: Internet
Author: User

######  binary Automatic installation database script root password 123456 put the script and the installation package in the/USR/LOCAL/SRC directory to #################### #数据库目录/usr/local/mysql##### ############ #数据目录/data/mysql################# #慢日志目录/data/slowlog################# #端口号默认3306其余参数按需自行修改 ######### ####!/bin/bashcd /usr/local/src/wget   http://ftp.kaist.ac.kr/mysql/downloads/mysql-5.7/ Mysql-5.7.20-linux-glibc2.12-x86_64.tar.gzyum install -y autoconf automake imake  libxml2-devel expat-devel cmake gcc gcc-c++ libaio libaio-devel bzr  bison libtool ncurses5-devel# check if user is rootif [ $ ( id -u)  !=  "0"  ]; then    echo  "error: you must  be root to run this script, please use root to install "    exit 1ficlearecho " ======================================================== ================= "ECHO&NBSP; " a tool to auto-compile & install mysql 5.7.20 on redhat/ centos linux  "echo " ========================================================================= " cur_dir=$ (PWD) #set  mysql root password    echo  "====================== ===== "    mysqlrootpwd=" 123456 "    echo -e " please  Input the root password of mysql: "    read -p " (Default  password: 123456): " mysqlrootpwd    if [ " $mysqlrootpwd " =   ""  ]; then        mysqlrootpwd= "123456"      fi    echo  "==========================="     echo   "Mysql root password: $mysqlrootpwd"     echo  "======================== = = = "#which  mysql&nbSp version do you want to install?echo  "==========================="      isinstallmysql57= "n"     echo  "install mysql 5.7.20,please  Input y "    read -p " (please input y , n): "  isinstallmysql57    case  "$isinstallmysql"  in    y| y| yes| yes|yes|yes|yes| Yes|yes)     echo  "you will install mysql 5.7.20"      isinstallmysql57= "Y"     ;;     *)     echo  "input error,you will exit  install mysql 5.7.20 "    isinstallmysql57=" n "    exit     esac    get_char ()     {     savedstty= ' Stty -g '     stty -echo    stty cbreak     #dd  if=/dev/tty bs=1 count=1 2 > /dev/null    stty -raw    stty echo     stty  $SAVEDSTTY     }    echo  "     echo  "press any key to start...or press ctrl+c to  Cancel "    char= ' Get_char '              # Initialize  the installation related content.function  Initinstall () {    cat /etc/issue    uname -a     memtotal= ' free -m | grep mem | awk  ' {print  $2} '      echo -e  "\n memory is: ${memtotal} mb "       #Set  timezone&nbsP;   rm -rf /etc/localtime    ln -s /usr/share/zoneinfo /asia/shanghai /etc/localtime     #Delete  Old Mysql program     rpm -qa|grep mysql    rpm -e mysql     #Disable  selinux    if [ -s /etc/selinux/config ]; then     sed -i  ' s/selinux=enforcing/selinux=disabled/g '  /etc/selinux/config &NBSP;&NBSP;&NBSP;&NBSP;FI&NBSP;&NBSP;&NBSP;&NBSP;SETENFORCE&NBSP;0} #Installation  of depend on  and optimization options.function installdependsandopt () {cd  $cur _dircat > >/etc/security/limits.conf<<eof* soft nproc 65535* hard nproc 65535*  soft nofile 65535* hard nofile 65535EOFecho  "fs.file-max=65535"  > &GT;&NBSP;/ETC/SYSCTL.CONF}#Install  mysqlfunction installmysql57 () {echo  "============================install mysql  5.7.20================================== "cd  $cur _dir#backup old my.cnf#rm -f / Etc/my.cnfif [ -s /etc/my.cnf ]; then    mv /etc/my.cnf  /etc/my.cnf. ' date +%y%m%d%h%m%s ' .bakfiecho  ' ============================mysql 5.7.20  installing............========================= "#mysql  directory configurationcd /usr/local/ srctar   zxvf     mysql-5.7.20-linux-glibc2.12-x86_64.tar.gzmv    mysql-5.7.20-linux-glibc2.12-x86_64       /usr/local/ mysqlgroupadd mysql -g 512useradd -u 512 -g mysql -s /sbin/ Nologin -d /home/mysql mysqlmkdir -p /data/mysqlmkdir -p /data/slowlogchown  -r mysql:mysql /data/mysqlchown -r mysql:mysql /usr/local/mysqlchown -r mysql:mysql /data/slowlogmkdir -p  /var/run/mysql chown mysql:mysql /var/run/mysql#edit /etc/my.cnfserverid= ' Ifconfig  eth0 | grep  "inet"  | awk  ' { print $2} ' | awk -f.  ' { print $3$4} ' cat >>/etc/my.cnf<<eof[client]port=3306socket=/var/run/mysql/ mysql.sockdefault-character-set=utf8[mysql]no-auto-rehashdefault-character-set=utf8[mysqld]bind-address =  0.0.0.0port=3306character-set-server=utf8socket=/var/run/mysql/mysql.sockbasedir=/usr/local/mysqldatadir =/data/mysqlexplicit_defaults_for_timestamp=truelower_case_table_names=1back_log=103max_connections=3000max_ Connect_errors=100000table_open_cache=512external-locking=falsemax_allowed_packet=32msort_buffer_size=2mjoin_ buffer_size=2mthread_cache_size=51query_cache_size=32m#query_cache_limit=4mtransaction_isolation= Repeatable-readtmp_table_size=96mmax_heap_table_size=96m###***slowqueryparameterslong_query_time=1slow_query_log = 1slow_query_log_file= /data/slowlog/slow.log###***binlogparameterslog-bin=mysql-binbinlog_cache_size=4mmax_binlog_cache_size= 4096mmax_binlog_size=1024mbinlog_format=mixedexpire_logs_days=7###***relay-logparameters#relay-log=/data/3307/ Relay-bin#relay-log-info-file=/data/3307/relay-log.info#master-info-repository=table#relay-log-info-repository =table#relay-log-recovery=1#***myisamparameterskey_buffer_size=16mread_buffer_size=1mread_rnd_buffer_size= 16mbulk_insert_buffer_size=1m#skip-name-resolve###***master-slavereplicationparametersserver-id= $SERVERID # Slave-skip-errors=all#***innodbstorageengineparametersinnodb_buffer_pool_size=4ginnodb_data_file_path=ibdata1 : 10m:autoextend#innodb_file_io_threads=8innodb_thread_concurrency=16innodb_flush_log_at_trx_commit=1innodb_log _buffer_size=16minnodb_log_file_size=512minnodb_log_files_in_group=2innodb_max_dirty_pages_pct=75innodb_buffer _pool_dump_pct=50innodb_loCk_wait_timeout=50innodb_file_per_table=on[mysqldump]quickmax_allowed_packet=32m[myisamchk]key_buffer=16msort_ buffer_size=16mread_buffer=8mwrite_buffer=8m[mysqld_safe]open-files-limit=8192log-error=/data/mysql/ error.logpid-file=/data/mysql/mysqld.pideof/usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf - -user=mysql  --datadir=/data/mysql    --basedir=/usr/local/mysql    --initialize-insecurecp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqldsed  -i  ' s/' hostname '/mysqld/g '   /etc/init.d/mysqldchmod 700 /etc/init.d/ Mysqldchkconfig --add mysqldchkconfig --level 2345 mysqld oncat >>  /etc/ld.so.conf.d/mysql-x86_64.conf<<EOF/usr/local/mysql/libEOFldconfigif [ -d  "/ Proc/vz " ];thenulimit -s unlimitedfi/etc/init.d/mysqld startcat >> /etc/ Profile <<eofexport path= $PATH:/usr/local/mysql/binexport ld_library_path= $LD _library_path:/usr/local/mysql/libeof/usr/local/mysql/bin/ mysqladmin -u root password  $mysqlrootpwdcat  > /tmp/mysql_sec_script<< eofuse mysql;delete from mysql.user where user!= ' root '  or host!= ' localhost ' ; #grant  all privileges on *.* to  ' sys_admin ' @ '% '  identified by  ' 123456 ';flush privileges; eof/usr/local/mysql/bin/mysql -u root -p$mysqlrootpwd -h localhost <     /tmp/mysql_sec_scriptrm -f /tmp/mysql_sec_script/etc/init.d/mysqld  restartecho  "============================mysql 5.7.20 install completed=================== ====== "}function checkinstall () {echo " ===================================== check install  =================================== "clearismysql=" "echo " Checking ... "if [ -s /usr/LOCAL/MYSQL/BIN/MYSQL&NBSP;]&NBSP;&AMP;&AMP;&NBSP;[&NBSP;-S&NBSP;/USR/LOCAL/MYSQL/BIN/MYSQLD_SAFE&NBSP;]  && [ -s /etc/my.cnf ]; then  echo  "Mysql: ok"    ismysql= "OK"   else  echo  "Error: /usr/local/mysql not found!!! Mysql install failed. " fiif [  "$ismysql"  =  "OK"  ]; thenecho  "install mysql 5.7.20 " Completed! enjoy it. " echo  "=========================================================================" Netstat -ntlelseecho   "sorry,failed to install mysql!" echo  "You can tail /root/mysql-install.log from your server." FI} #The  installation loginitinstall 2>&1 | tee /root/ mysql-install.loginstalldependsandopt 2>&1 | tee -a /root/ Mysql-install.loginstallmysql57 > /dev/nullcheckinstaLl 2>&1 | tee -a /root/mysql-install.logcd /usr/local/src#rm -f  mysql-5.7.20-linux-glibc2.12-x86_64.tar.gzsource  /etc/profile Backup Mysqldump  -uroot  -p123456 -B  ultrax  > ultrax.sql-A   Full Backup-b   Backup Library (table structure and data) view egrep -v  "#|\*|--|^$"     ultrax.sql recovery mysql  -uroot - P123456        < /root/ultrax.sql

This article is from the "what-all" blog, please be sure to keep this source http://hequan.blog.51cto.com/5701886/1982428

mysql-5.7.20 Binary Installation | Backup recovery

Related Article

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.