Script mode Quick Create MySQL from library with one click

Source: Internet
Author: User
Tags free ssh

This assumes that we have already installed the mysql5.6 in the remote host, and the various parameters are basically consistent with the main library, the main library can be password-free SSH login to the slave library, the master and subordinate libraries are installed xtrabackup.


Assume the main library address: 192.168.2.11

From library address to be configured: 192.168.2.12


Script below, write the comparison rotten, Pat:

#!/bin/bash#  a key to create from the library, you need to ensure that this function ssh password-free login to the slave library machine. You need to make sure that the machine's time is synchronized. #  write the comparison rotten, have time to change again. # date: 2017/02/10 by  a dish chicken echo  "##################################################### ################################ #请确保从库的server-id is not the same as this machine, and other parameters related to the log class are as consistent as possible with this machine. (The script in the default from the library's datadir to/data/mysql) Here we have already performed on the main library to create the synchronization of the account of the SQL, and the main library can ssh key way to log in from the library machine 10s you can CTRL + C cancel the execution of this script ############## ######################################################################## "sleep 10#  to be configured from the library Ipremote_ host= ' 192.168.2.12 ' #  native MySQL configuration information user= ' root ' pass= ' [email protected] ' socket= '/tmp/mysql.sock ' #  Define three functions Function init_remote () {  #  install LZ4 to the remote host, create the directory that holds the backup files   ssh [email  Protected] $REMOTE _host  ' yum install lz4 -y '   ssh [email protected]$ remote_host  ' Mkdir /tmp/mysql -p '}function copy_to_remote ()  {  #  This backup method is referenced from the Kang Daniel's public number   /usr/bin/innobackupex --user= $USER  --password= $PASs --parallel=4 --socket= $SOCKET  --no-timestamp --stream=xbstream . |   Lz4 -b4 |  ssh [email protected] $REMOTE _host    "cat - |  lz4 -d -b7 | xbstream -x -c /tmp/mysql "}function apply_to_remote   () {  ssh [email protected] $REMOTE _host  ' innobackupex --apply-log /tmp /mysql/'   ssh [email protected] $REMOTE _host  '/bin/rm -fr /data/mysql/* '   ssh [email protected] $REMOTE _host  ' mv /tmp/mysql/* /data/mysql/'    ssh [email protected] $REMOTE _host  ' chown mysql.mysql /data/mysql/ -r '   ssh [email protected] $REMOTE _host  '/etc/init.d/mysqld start '}#  Perform the above 3 functions in turn init_remote | |  echo  "Init_remote failed. exit" copy_to_remoteapply_to_remote | |  echo  "apply&Nbsp;to remote failed. exit "echo " ######################################################## ###################### #从库的数据已经同步完成, also need to go from library to modify my.cnf  in [Mysqld] segment plus relay_log = mysql-relay.bin  Restart the database, and then log in to the database to execute:reset master; and then execute change master to instructions, and then start slave;. The format is as follows: change master to   master_host= ' 192.168.2.11 ',     master_ User= ' Repluser ',    master_password= ' [email protected] ',    master_port=3306,    master_log_file= ' mysql-bin.000012 ',   master_log_pos=500,    master_connect_retry=10,   master_heartbeat_period=60; ################################### ############################################"


This allows you to directly

Script mode Quick Create MySQL from library with one click

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.