Mysql database experience from finishing the master

Management mysql master-slave more than 2 years, and has managed more than 200 sets mysql master-slave, involving almost all versions of master and slave, this blog belongs to concluding, in part, taken from the network, mostly based on the experience to manage and experience written, collate it, and colleagues to share, we want to help, communicate with each other.

  A, mysql master-slave principle

  1, Replication thread

  Replication of Mysql is an asynchronous replication process (mysql5.1.7 above into semi-synchronous and asynchronous replication modes), (we call Master) copied from one to another Mysql Mysql instace instance (we call Slave) . The copy operation will be accomplished primarily achieved between the Master and Slave by the three threads, which two threads (threads and the Sql IO threads) Slave side, another thread (Thread IO) at the Master side.

  To achieve the MySQL Replication, you must first open the Master end of the Binary Log (mysql-bin.xxxxxx) function, can not be achieved otherwise. Because the whole process is actually a copy Slave from the Master side to obtain the log and then himself completely in the implementation of the order who log recorded in various operations. MySQL opened by using the Binary Log "-log-bin" parameter options in starting the MySQL Server or mysqld parameters ([mysqld] parameters after identification section) in the configuration file f is increased "log-bin" parameters item.

  2, the basic process MySQL replication follows:

  2.1. The above Slave IO thread connection Master, and requests the content from the log file in the specified location for the log (or from the beginning of the log) after;

  2.2. Master After receiving the request from the IO threads Slave reads the log information specifying the specified position after the log information according to the request is responsible for copying IO thread, the thread returns to the IO Slave end. Return information in addition to the information contained in the log, further comprising Binary Log file name and the position information of the Master side of this in return in the Binary Log;

  2.3. Slave IO thread after receiving the message, the content of the received log to sequentially write the endmost end Slave Relay Log file (mysql-relay-bin.xxxxxx), and the read end of the bin-log Master the file name and location records to master- info file to be able to clear high-speed Master "I need to log the contents of the location from which a bin-log of the start of the future, please send me" next time you read

  2.4. Slave SQL thread after detecting the Relay Log newly added content, will immediately parse the contents of the Log files become those statements in the Query Master side executable real time execution and implementation of these in their own Query. Thus, in fact in the Master and Slave-side end of the same Query performed, so the data it is exactly the same at both ends.

  3, Mysql replication of several models

  3.1 Starting MySQL 5.1.12, can be used to achieve the following three modes:

  - copy the SQL statement (statement-based replication, SBR) based,

  - Copy row (row-based replication, RBR) based,

  - Mixed mode replication (mixed-based replication, MBR).

  Accordingly, binlog format there are three types: STATEMENT, ROW, MIXED. MBR mode, SBR mode is the default.

  At runtime can dynamically change binlog format, except for the following situations:

  1. intermediate storage processes or trigger

  2. Enable the NDB

  3. The current session RBR trial mode, and it has opened a temporary table

  If binlog adopted MIXED mode, the mode will automatically change binlog RBR mode of SBR mode in the following situations:

  1. When DML statement updates a table when NDB

  2. When the function contains the UUID ()

  When comprising more than 3.2 and the table is updated field AUTO_INCREMENT

  4. perform any INSERT DELAYED statement

  5. When the UDF

  6. view must request the use of RBR, for example, the establishment of view is the use of the UUID () function

  3.2 from the master copy mode is set:

  log-bin=mysql-bin

  #binlog_format="STATEMENT"

  #binlog_format="ROW"

  binlog_format="MIXED"

  You can also dynamically modify the binlog format at run time. E.g

  mysql> SET SESSION binlog_format='STATEMENT';

  mysql> SET SESSION binlog_format='ROW';

  mysql> SET SESSION binlog_format='MIXED';

  mysql> SET GLOBAL binlog_format='STATEMENT';

  mysql> SET GLOBAL binlog_format='ROW';

  mysql> SET GLOBAL binlog_format='MIXED';

  3.3 modes respective advantages and disadvantages:

  SBR advantages:

  Has a long history, skills mature

  binlog file smaller

  binlog contains all the information database modifications, could then be reviewed security of the database, etc.

  binlog can be used for real-time reduction, not just for copying

  Main can be different from the version, can be high from the server version than the main server version

  SBR disadvantages:

  Not all UPDATE statements can be copied, especially when containing uncertain operation.

  When the UDF call has a copy uncertainties may be out of question

  The following functions use statements can not be copied:

  * LOAD_FILE()

  * UUID()

  * USER()

  * FOUND_ROWS()

  * SYSDATE () (-sysdate-is-now option unless startup is enabled)

  INSERT ... SELECT will produce more than RBR row-level locking

  When copying the need to perform a full table scan (WHERE statement is not applied to the index) UPDATE, RBR need to request more than the row-level locks

  For InnoDB tables have AUTO_INCREMENT field concerned, INSERT statements block other INSERT statements

  For some complex statements, in more serious cases from consumption of resources on the server, and the next RBR mode, it will only have an impact on that record changes

  Storage function (not stored procedures) will be executed once at the same time is called NOW () function, this can be said to be a bad thing might be a good thing

  It determines the need to run on the UDF from the server

  Data tables and master server must almost be consistent. Otherwise, it can cause replication errors

  Perform complex sentence if wrong, will consume more resources

  RBR advantages:

  Any situation can be copied, which copy is the most secure and reliable

  Copy and skills, like most other database systems

  In most cases, from the table on the server if the primary key, then it will copy a lot faster

  Fewer row locks when copying the following statement:

  * INSERT … SELECT

  * INSERT contain AUTO_INCREMENT field

  * No strings attached or not to modify a lot of records UPDATE, or DELETE statement

  Execute INSERT, UPDATE, DELETE statement when fewer locks

  Copy from multiple threads to execute on the server possible

  RBR disadvantages:

  binlog much larger

  When the rollback binlog complex will contain large amounts of data

  UPDATE statement is executed, all changes will be recorded in written binlog on the master server, and SBR will only write once, which can lead to frequent binlog concurrent write questions

  UDF produce large BLOB value will result in slower replication

  Can not be seen from the binlog are replicated what to write statements (encrypted)

  When the implementation of a SQL statement on the accumulation of non-transactional tables, the best use of SBR mode, it will easily lead to the occurrence of the master server from the data inconsistencies

  Further, guidelines for the processing time of the system inside the library mysql table changes as follows:

  If this is the case of using INSERT, UPDATE, DELETE direct action table, the log format according to the setting of the recording binlog_format

  If you are using GRANT, REVOKE, SET PASSWORD statement and other management to do, then in any case the use of SBR mode recording.

  Note: With RBR mode, can handle a lot of the primary key duplication originally appeared. Example:

  For insert into db_allot_ids select * from db_allot_ids this statement:

  In BINLOG_FORMAT = STATEMENT mode:

  BINLOG log information:

  —————————————–

  BEGIN

  ;

  # at 173

  #090612 16:05:42 server id 1 end_log_pos 288 Query thread_id=4 exec_time=0 error_code=0

  SET TIMESTAMP=1244793942;

  insert into db_allot_ids select * from db_allot_ids

  ;

  —————————————–

  In BINLOG_FORMAT = ROW mode:

  BINLOG log information:

  —————————————–

  BINLOG '

  hA0yShMBAAAAMwAAAOAAAAAAAA8AAAAAAAAAA1NOUwAMZGJfYWxsb3RfaWRzAAIBAwAA

  hA0yShcBAAAANQAAABUBAAAQAA8AAAAAAAEAAv / 8AQEAAAD8AQEAAAD8AQEAAAD8AQEAAAA =

  ';

  —————————————–

  4, Mysql from the main advantages and disadvantages

  MySQL master-slave synchronization is a very mature infrastructure, the advantages are: ① in can perform queries work (that is, we often say that the reading function) from the server, reducing the main server stress; ② the backup from the primary server to avoid the impact during backup master service; ③ a problem if the primary server, the server can be switched from. So I often use this program in project deployment and implementation; mysql in view of the production environment of rigor.

  In fact, in the old version, MySQL replication is not achieved by the end of the Slave IO thread and the SQL thread two threads work together to complete, but all the work is done by a separate thread. But MySQL's engineers soon discovered that there is a big risk to do so and performance issues, notably the following:

  First of all, if by a single thread to independently implement this work, then it makes copying Master side, Binary Log logs, and parsing these logs, and then in the process itself performs the process of becoming a serial, performance will naturally be compared big limitations, Replication delay in this architecture naturally relatively long.

  Secondly, Slave end of this thread gets copied from the Master Binary Log come after the end, we need to then parse the content, restore the original Query Master end executed, and then execution itself. In this process, Master terminal is likely they have generated a lot of changes and generate a great deal of Binary Log information. If there is a fault can not be repaired at the end of this storage system Master stage, then at this stage all the changes arising will be lost forever and can not get it back. This potential risk is particularly prominent in the Slave-side pressure is relatively large, because if the Slave pressure is relatively large, analytic applications, and log time spent on these logs will naturally be longer, it may lose data also will be more.

  So, in the latter part of the transformation, the new version of MySQL in order to minimize this risk and improve the performance of replication, copy Slave end was changed two threads to complete, that is, the aforementioned IO thread and the SQL thread. The first to propose improvements Yahoo! is an engineer "Jeremy Zawodny". Through this transformation, then it will largely solve the performance problems, to shorten the delay time of asynchronous, while also reducing the potential amount of data loss.

  Of course, even replaced the two threads so now to collaborate after, also still the possibility of Slave data latency and data loss there is, after all, this replication is asynchronous. Changing long as the data is not in a transaction, these problems are there.

  If you want to completely avoid these problems, you can only use the MySQL Cluster to solve. But the MySQL Cluster know I wrote this part of the time, it is still a solution in-memory database, which is required of all data including the index all Load into memory, this requires a very large large memory, for the general popularity of applications can be implemented is not too large. MySQL is now continuous improvement to achieve its Cluster, in which a very large change is to allow all data without Load into memory, but merely an index of all Load into memory, I would like to believe after the completion of the transformation of the MySQL Cluster will more popular, can be implemented will be greater.

  5, Mysql semi-synchronous mode (Semisynchronous Replication)

  We know that before 5.5, MySQL replication is asynchronous operation in fact, not synchronized, which means allowing the existence of data between master and slave a certain delay, mysql original purpose of this design may also be based on the availability of consideration, in order to ensure the master affected by the slave and master asynchronous replication that is optimal one property states: wait for the operation without the need to submit a completed slave finished binlog. So there is a risk, when you use the slave as a backup if the master hang up, then the transaction section has been submitted unsuccessfully transmitted to the slave might exist, which means that data loss!

  In MySQL5.5 version, the introduction of semi-synchronous replication mode (Semi-synchronous Replication) can be successful (but opposite) to avoid the above risks data loss. Will be submitted after the master will wait until binlog successfully transferred and written at least one slave's relay log, or wait until the timeout (default 10s): in this mode. When the timeout occurs, master will automatically switch the semi-synchronous to asynchronous, until at least one slave successfully receive and send Acknowledge, master will then switch back to the semi-synchronous mode. Combined with this new feature, we can do to ensure the absolute safety of the premise allows data synchronization loss of certain transaction throughput down, because when you set the timeout for the case of a sufficiently large value of any data submitted will be safe arrival slave.

  mysql5.5 version supports semi-synchronous replication (Semisynchronous Replication), but not the native support, through the plugin to support, and the default is not installed this plug-in. Whether binary distribution, or compile your own source code will be generated by default this plugin, one for a master it is for the slave, before use maybe need to install plugins.

  Two, Mysql copied from the master filter

  Copy the filter there are two ways:

  1, in the event the primary server into two filtered from the system log, the relevant parameters are: binlog_do_db and binlog_ignore_db.

  2, the event filtering from the server from the relay log out in the relevant parameter is replicate_ *.

  Copy only be extended to read, write can not be extended, partition the data can be written to be extended.

  Copy optimization:

  In mysql replication environment, there are eight parameters allows us to control, want to ignore the need to copy or not to copy DB or table are:

  The following two needs to be set on the Master:

  Binlog_Do_DB: set which databases need to record Binlog

  Binlog_Ignore_DB: Where the database does not need to set the record Binlog

  The advantage of reducing the amount of Io Binlog end of the recording Master brings, reduce network IO, IO thread will allow slave side, to reduce the SQL thread to dramatically improve replication performance,

  The disadvantage is the need to determine whether mysql replication is not based on an event generated DB query where the event, but according to the default specified when the database query execution time where (ie login name of the library or run "use database" specified in the DB ), only when fully consistent with the current default configuration DB and DB set in the IO thread will read the event to slave IO thread. so, if not the same as under the DB and DB the default settings need to replicate conditions change the data in a DB Table in need of replication, the event is not copied to Slave to go, which would result in inconsistent data and Master of Slave-side data. Also, do not change the default database data in the database replication needs, it will be copied to the slave terminal, when the terminal is not the slave database, replication will result in an error and stops.

  The following six on the need to set up slave:

  Replicate_Do_DB: set the desired replicated database, a plurality of DB separated by commas

  Replicate_Ignore_DB: setting negligible database.

  Replicate_Do_Table: Table setting you want to copy

  Replicate_Ignore_Table: Table setting negligible

  Replicate_Wild_Do_Table: function with Replicate_Do_Table, but can be set with a wildcard.

  Replicate_Wild_Ignore_Table: function with Replicate_Do_Table, function with Replicate_Ignore_Table, can take a wildcard.

  The advantage is set up replication filtering mechanism in the slave side, we can ensure that mistakes will not be a problem because the default database problems caused by inconsistent or copy Slave and Master data.

  The disadvantage is performance worse than the Master side because: regardless of whether it is necessary to copy, the event will be read IO threads to the Slave-side, so that not only increase the network IO volume, but also to the IO thread Slave end increased Relay Log write intake.

  Note: In the actual production applications found in previous versions mysql5.0, mysql this filter settings is almost non-existent, does not work: whether you set up in the main library or from the library or ignore a database table he will still be synchronized, so do 5.0 in the previous version of the master synchronization from, be sure to keep the consistency of the database from the master, the master database or table from some of the must have, or an error occurs during synchronization.

  Three, Mysql master-slave synchronization Configuration

  Main Library IP: 192.168.1.2

  From the library IP: 192.168.1.3

  For the user to add a master-slave synchronization:

  GRANT REPLICATION SLAVE ON *.* TO 'repl'@'%' IDENTIFIED BY ‘1q2w3e4r’;

  If the monitoring mysql master-slave, please add a super permission:

  GRANT SUPER, REPLICATION SLAVE ON *.* TO 'repl'@'%' IDENTIFIED BY '1q2w3e4r';

  1, the configuration of the main library

  1.1. The following version of the configuration mysql5.0

  Modify the main library mysql Configuration file, add the following to the [mysqld] section:

  server-id=1

  log-bin=/home/mysql/logs/binlog/bin-log

  max_binlog_size=500M

  binlog_cache_size=128K

  binlog-do-db=adb

  binlog-ignore-db=mysql

  log-slave-updates

  1.2. Mysql5.0 above configuration

  Modify the main library mysql Configuration file, add the following to the [mysqld] section:

  server-id=1

  log-bin=/home/mysql/logs/binlog/bin-log

  max_binlog_size=500M

  binlog_cache_size=128K

  binlog-do-db=adb

  binlog-ignore-db=mysql

  log-slave-updates

  expire_logs_day=2

  binlog_format="MIXED"

  1.3 Meaning of the various parameters and related items Note:

  server-id = 1 # server flag number, note that a plurality of such identification can not appear in the configuration file, if a plurality of first words appear mysql to prevail, from which a set of main identification number can not be repeated here.

  log-bin = / home / mysql / logs / binlog / binlog # open binlog, and specify the file directory and file name prefix.

  max_binlog_size = 500M # The maximum size of each bin-log, when this size is equal to 500M automatically generates a new log file. Not write a record in two log files, so sometimes the log file exceeds this size.

  binlog_cache_size = 128K # log cache size

  binlog-do-db = database name adb # need to be synchronized, if it is more, you can write a line in this format.

  binlog-ignore-db = mysql # database name do not need to sync, if it is more, you can write a line in this format.

  log-slave-updates # updated when Slave reads the log from the new Master database written to the log, if only start log-bin but does not start log-slave-updates the Slave records only for their own database update operations.

  expire_logs_day = number of days to keep the bin-log log file # 2 is set, this version does not support the following parameters mysql5.0.

  binlog_format = "MIXED" # Set bin-log log file format: MIXED, duplicate primary key can be prevented.

  2, from the library configuration

  2.1.mysql5.1.7 previous versions

  Modify the configuration profile from the library mysql, add the following in the [mysqld] section:

  server-id=2

  master-host=192.168.1.2

  master-user=repl

  master-password=1q2w3e4r

  master-port=3306

  master-connect-retry=30

  slave-skip-errors=1062

  replicate-do-db=adb

  replicate-ignore-db=mysql

  slave-skip-errors=1007,1008,1053,1062,1213,1158,1159

  master-info-file=/home/mysql/logs/

  relay-log=/home/mysql/logs/relay-bin

  relay-log-index=/home/mysql/logs/relay-bin.index

  relay-log-info-file=/home/mysql/logs/

  If you modify the relevant information to connect the main library, be sure to delete the file before restarting, or after the restart because the connection information changes from the library and does not automatically connect the main library, causing synchronization to fail. This file is saved connecting the main repository of information.

  2.2.mysql5.1.7 later

  Mysql5.1.7 version of the configuration database in the cluster above small, mainly using the new synchronization information recording, he does not support the configuration information about connecting the main library in the configuration file, but to connect other relevant information recorded in the master- change info-file = / home / mysql / logs / file, if the storage has changed, direct mysql command line connection information to take effect, the more flexible, without having to restart mysql. Modify the configuration profile from the library mysql, add the following in the [mysqld] section:

  slave-skip-errors=1007,1008,1053,1062,1213,1158,1159

  2.3 The meaning of each parameter and items related note

  Here talk about two parameters, it is connected to all the other master library and the library information from the intermediate relay-log log settings.

  master-connect-retry = 30 # This option controls the retry interval, the default is 60 seconds.

  slave-skip-errors = 1007,1008,1053,1062,1213,1158,1159 # out of this is to ignore the error during synchronization, these errors do not affect the integrity of the data, something often wrong, and generally setting ignored . 1062 in which the primary key duplication error.

  3, master-slave synchronization to achieve

  3.1 unified database

  Check the main configuration file from the database to see if properly configured. The first time synchronization to back up the database on the main library need to synchronize, and then imported into the full from the library. Note: The previous version mysql5.0 involve itself mysql replication problems filtering, we need to back up all databases into Cong library maintained.

  3.2. Check and record the main library bin-log information

  Mysql into the main repository, perform: show master status; following appears:

  mysql> show master status;

  +-------------+----------+--------------+------------------+

  | File        | Position | Binlog_do_db | Binlog_ignore_db |

  +-------------+----------+--------------+------------------+

  | bin-log.003 | 4        | adb          | mysql            |

  +-------------+----------+--------------+------------------+

  1 row in set (0.00 sec)

  Record File Position and information;

  3.3. Perform synchronization on the statement from the library

  Enter mysql, execute the following statement:

  slave stop;

  change master to

  master_host='192.168.1.2',

  master_user='repl',

  master_password='1q2w3e4r',

  master_port=3306,

  master_log_file='bin-log.003',

  master_log_pos=4;

  slave start;

  3.4. Check master-slave synchronization status

  Enter mysql, execute show slave statusG; shown below (different results for different queries mysql version, but the important indicators still the same):

 

Important indicators:

  Slave_IO_Running: Yes

  Slave_SQL_Running: Yes

  Master_Log_File: bin-log.003

  Relay_Master_Log_File: bin-log.003

  Read_Master_Log_Pos: 4

  Exec_master_log_pos: 4

  Seconds_Behind_Master: 0 (prior to version 5.0 does not have this option)

  Above options corresponding twos, as long as the results are consistent, it shows the success of master-slave synchronization.

  3.5. Common errors and handle synchronization in

  1, phenomenon: the show slave statusG from the library above; the following conditions,

  Slave_IO_Running: Yes

  Slave_SQL_Running: No

  Seconds_Behind_Master: NULL

  the reason:

  . A program may be a write operation on the slave;

  . B may be the slave machine restart, transaction rollback caused;

  c. There may be experiencing some sort of error during synchronization, this will see an error message when viewing from the state library, the most rare is the primary key to repeat 1062 mistakes.

  Solution:

  Into the master

  mysql> show master status;

  +----------------------+----------+--------------+------------------+

  | File | Position | Binlog_Do_DB | Binlog_Ignore_DB |

  +----------------------+----------+--------------+------------------+

  | mysql-bin.000040 | 324 |adb | mysql|

  +----------------------+----------+--------------+------------------+

  And then perform a manual synchronization on the slave server

  slave stop;

  change master to

  master_host='10.14.0.140',

  master_user='repl',

  master_password='1q2w3e4r',

  master_port=3306,

  master_log_file='mysql-bin.000040',

  master_log_pos=324;

  slave start;

  show slave statusG;

  2, phenomenon: not synchronize the database, show slave status display:

  Slave_IO_Running: No

  Slave_SQL_Running: Yes

  Seconds_Behind_Master: NULL

  Solution: First check err log database to see what is wrong prompt to see if IP, user, password and other information connected to the main library from the library is wrong, if wrong, to re-synchronize; the confirmation, restart the main database.

  mysql> show master status;

  +------------------+----------+--------------+------------------+

  | File | Position | Binlog_Do_DB | Binlog_Ignore_DB |

  +------------------+----------+--------------+------------------+

  | mysql-bin.000001 | 98 | adb| mysql|

  +------------------+----------+--------------+------------------+

  Enter from the library mysql, execute:

  slave stop;

  change master to Master_Log_File='mysql-bin.000001',Master_Log_Pos=98;

  slave start;

  Or this:

  stop slave;

  set global sql_slave_skip_counter=1;

  start slave;

  This phenomenon is mainly a problem in the master database, the connection of the main library information error, hang up if the main library database common mistake caused by other reasons, I will restart the master in the actual operation after the restart slave to solve this problem, this occurs the problem must be to restart the master database.

  Four, mysql Lord Lord and the main cluster

  1, mysql main main implementation

  In the actual production applications, in order to collapse or master server in the main library severe fault fast recovery business, will switch directly into the library, when the main library resolving the problem to let him direct a bundle libraries to run, this the Lord is when a good choice.

  Five, mysql master-slave monitoring

  In the application mysql master-slave, as long as a reasonable set, basically not a problem, but he was monitoring is essential in order to avoid problems due really do not know and unnecessary data loss.

  1, the main idea mysql master-slave monitoring

  Mysql from the main monitor, which is mainly to monitor some important parameters from the library:

  Slave_IO_Running: Yes

  Slave_SQL_Running: Yes

  Master_Log_File: bin-log.003

  Relay_Master_Log_File: bin-log.003

  Read_Master_Log_Pos: 4

  Exec_master_log_pos: 4

  Seconds_Behind_Master: 0 (prior to version 5.0 does not have this option)

  Reflect the above parameters from the main library and the library status is normal, whether from the library behind the main library and so on. It is worth mentioning that in mysql5.0 previous version, Slave_IO_Running not reliable indicators of the state, will become the main library in the case of NO direct hang, Seconds_Behind_Master parameter does not exist. More monitoring parameters can be monitored from the main mysql.

  2, mysql to achieve from the main monitor

  Regardless of which version is mysql, wherein Exec_Master_Log_Pos from the library, Exec_master_log_pos; Log_File, Position Master on the primary database, these four parameters can be determined from the current state of the master. The following is applicable to all mysql version of the master from the monitoring shell script:

  # / Bin / sh user = repl passwd = 123415 master_ip = "192.168.1.2" log = "/ data3 / check_repl.log" value () {master = `/ usr / local / mysql / bin / mysql -u $ user - p $ passwd -h $ master_ip -e "show master statusG;" | egrep "File | Position" `#mysql 4.0 slave =` / usr / local / mysql / bin / mysql -u $ user -p $ passwd -h127. 0.0.1 -e "show slave statusG;" | egrep "Relay_Master_Log_File | Exec_master_log_pos" `#mysql 5.0 # slave =` mysql -u $ user -p $ passwd -e "show slave statusG;" | egrep "Relay_Master_Log_File | Exec_Master_Log_Pos" `# current log position bin-log, and write on the take primary database Master_Log =` echo $ master | awk '{print $ 2}' | "." awk -F '{print $ 2}' `Master_Log_Pos =` echo $ master | awk '{print $ 4}' `# taken from the library of the current sync master repository location Relay_Master_Log_File =` echo $ slave | awk '{print $ 2}' | "." awk -F '{print $ 2}'` Exec_Master_Log_Pos=`echo $slave |awk '{print $4}'` echo "Master_Log:"$Master_Log>>$log echo "Master_Log_Pos:"$Master_Log_Pos>>$log echo "Relay_Master_Log_File:"$Relay_Master_Log_File>>$log echo "Exec_Master_Log_Pos:"$Exec_Master_Log_Pos>>$log } for((i=1;i<=10;i++)); do echo "#################################">>$log value time=`date +"%Y-%m-%d %H:%M:%S"` if [ $Master_Log -eq $Relay_Master_Log_File ];then A=`expr $Master_Log_Pos - $Exec_Master_Log_Pos` if [ $A -lt 0 ];then A=`expr 0 - $A` fi echo $A>>$log if [ $A -lt 10000 ];then echo "$time Master-Slave is OK.">>$log #echo "$i" break else if [ $i ge 3 ];then echo "$time Warning:Slave-Master lag $A " >>$log echo "$i"fi sleep 30 continue fi else sleep 60 fi if [ $i -eq 10 ];then echo "$i" echo "$time Error:Slave-Master must be check !" >>$log fi done

  Mysql5.0 in later versions, mysql master-slave is already quite mature, and can monitor only Slave_IO_Running, Slave_SQL_Running, Seconds_Behind_Master state on it, it will not be explained.

Guess you like

Origin www.cnblogs.com/mysql-sql/p/11018450.html