1. there is no incremental backup mechanism for mysql databases. backup is a big problem when the data volume is too large. Fortunately, the mysql database provides a master-slave backup mechanism, which is to write all the data of the master database to the backup database at the same time. Achieve hot backup of mysql database. UYN? Bqz? LZTS2. to achieve dual-host hot backup, you must first understand the master-slave dual-host hot backup.
1. there is no incremental backup mechanism for mysql databases. backup is a big problem when the data volume is too large. Fortunately, the mysql database provides a master-slave backup mechanism, which is to write all the data of the master database to the backup database at the same time. Achieve hot backup of mysql database. U'yn? Bqz?
LZTS
2. to achieve dual-host hot standby, you must first understand the version requirements of the master-slave database server. To enable hot standby mysql versions, both must be higher than 3.2. another basic principle is that the database version of the slave database can be higher than that of the master server database, but it cannot be earlier than the database version of the master server. DP9 % x9y4O
Xq8-n
3. set master database server: Xo # S1
"BC
A. check whether the master server version supports hot standby. View my. cnf (unix-like) or my. in ini (windows), does the configuration of mysqld configuration block have log-bin (record database change logs), because mysql replication mechanism is log-based replication mechanism, therefore, the master server must support log changes. Set the database to which logs are to be written or the database to which logs are not to be written. In this way, only changes to the database you are interested in are written into the database log. P6/U = V
Pvk aO % YI
Server-id = 1 // database id. the default value is 1 and no change is required. W; BX: HZ
, P. BDs
Log-bin = log_name // name of the log file. you can specify the name of the log file to another directory. If no value is set, the log name of the default host name tZ * [7 $ Rq + k
* Z 0B = n
Binlog-do-db = db_name // The database that records logs l, IC
Fy sj)
Binlog-ignore-db = db_name // database without logs} WlJ. W *)
L! WlOsC8
If there are more than one database with "," split, and then set the user account xp-ug0k to synchronize database],
H} aSTaB
Mysql> grant replication slave on *. * [PO> hb
! [Z! RX3n $>
-> TO 'repl' @ '% .mydomain.com' identified by 'slavepass'; _ 1; E "=!
, @ [3 S
In versions earlier than 4.0.2, because REPLICATION is not supported, use the following statement to implement this function k = 3xm '; 9
VK] G *&
Mysql> grant file on *. * @ 1 {Zc $ d5 =
XE "s0i, e
-> TO 'repl' @ '% .mydomain.com' identified by 'slavepass'; c] gx, (PB"
Zbatpd) X
Set the configuration file of the master server and restart the database $ YqJ | B
WLBqa N!
B. lock the existing database and back up the current data <+ s> & k <
FCVcJ] ^
Lock the database! S h * je; k
; U {% H ~ /V.
Mysql> flush tables with read lock; M "g,; jZ & d
5sa, 2PL & c
There are two ways to back up a database: directly go to the mysql data directory and package the folder where you want to back up the database, the second method is to use mysqldump to back up the database, but the "-- master-data" parameter must be added. we recommend that you use the first method to back up the database Wn @ 6ovs.
WCncJ = y
C. view the status of the master server z + F * Bv] Y7
+ _ '0d' ph
Mysql> show master status \ G; UabQS * q4
UZ4x # (& 1
+ --------------- + ---------- + -------------- + ------------------ + 7 _~ _ LxC
B0 \ & di}-'0
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | 2; ak) Bgt
;) Bf/N ~
+ --------------- + ---------- + -------------- + -------------------- + Tpd {gt8 & Z
; 'U9 *
| Mysql-bin.003 | 73 | test | manual, mysql | I = w ~ | M
D6Ot:> Q"
+ --------------- + ---------- + -------------- + -------------------- + 6 ~ /6 [w [$ U
'_ | Io3'
Record the values of the File and Position items, which will be used later. ; X. q = [[>
_ BoJ &
D. then open the database lock {Q>: jmW +
SEy9; Su
Mysql> unlock tables; Z % Wf2o,
|) # & T \~ *
4. set slave server> $ j PQ
0 _ DG,> C
A. first set the database configuration file/kZ] m
Lk 'a0tw
Server-id = n // Set the database id. the default master server is 1, which can be set at will, but it cannot be repeated if there are multiple slave servers. P {L * ifK #
Q'y/uO + MpF
Master-host = db-master.mycompany.com // IP address or domain name of the master server c <Kmp6T
A67; j' * m
Master-port = 3306 // the port number of the master database XW. R: E #
\ AZb3h
Master-user = pertinax // synchronization database user p <} m \-k
Y = T; aK
Master-password = freitag // password for database synchronization 61 = "ylF
F: V? 1e G &
Master-connect-retry = 60 // if the master server is disconnected from the server, the time difference of the reconnection + 2 _!. PU =
P % F
Report-host = db-slave.mycompany.com // Server Reporting errors: P [| t_C $2
% ^ Iry | Fq
B. import the database backed up from the master database server to the slave server! MI] OB **
:?; F8] uY
C. start the slave database server. if the "-- skip-slave-start" parameter is not added during startup, the server enters mysql w "] Y $
(= WWXs
Mysql> slave stop; // stop the slave service {| N # I >@=
:-PZtjle
D. set various parameters of the master server: G' G) uUFm +
B = | qp * O] bp
Mysql> change master to s ~ Eqn 0 \!
T-dQ => }\
-> MASTER_HOST = 'master _ host_name ', // The IP address of the master server 4D [] = O $
& Z $ Ggf ^
-> MASTER_USER = 'replication _ user_name ', // database synchronization user ^ vQQ7; EP
H,; NO6
-> MASTER_PASSWORD = 'replication _ password', // synchronize the database password 9XT UB 'C
K {_ x) H @ _ %
-> MASTER_LOG_FILE = 'recorded _ log_file_name ', // file name of the binary log of the master server. the parameter Ygkj1Z must be remembered.
Lm} pai_ntr
-> MASTER_LOG_POS = recorded_log_position; // the start position of the log file (the parameter to be remembered earlier)> a/Vw @ nBU/
5'3% \ KB
E. start the synchronization database thread % bV0 =\= X
G ^ WzNu
Mysql> slave start; 'z0k. Gb
4x (pa
Check the database synchronization status. If synchronization is successful, congratulations! T ~ 5wulw'
2 +] ~ FCbU
View the status of the master/slave server] X # TZ + 8
+ JP} /
Mysql> show processlist \ G // You can check the mysql process to see if the monitored process is 3 l _ yx}
_ SrVC $ j
If the log is too large to clear the log, follow these steps: kx (h
S = 2 V + c 'G \
1. lock the primary database] k % g @ W
? LW $ LHa [y
Mysql> flush tables with read lock ;~
QL/: I4u]
2. stop the slave CaigYOanKb from the database.
Mtp> ^ ~ * K3
Mysql> slave stop; * l <= W4
] E) ^ & % _~
3. view the log file name and position of the log file of the master database [Fblr> e
Dp & O |/, Z?
Show master status; Oq +/2c/r
@ ^ (@ ZK8ym
+ --------------- + ---------- + -------------- + ------------------ + X: kDfEc6 (M
EQ6s j
| File | Position | Binlog_do_db | Binlog_ignore_db | c "ku5XMS
| V ~ /Ri] CQ
+ --------------- + ---------- + -------------- + -------------------- + 30ftb} <
W] W5WE | mv
| Louis-bin.001 | 79 | mysql |? WPt "lP
A53 = 0. n
+ --------------- + ---------- + -------------- + ------------------ +; 9b \/L? 0
?> Cdgn9 ^ w
4. unlock the master database lock CJDS +
} @ O ^ lO1C
Mysql> unlock tables; zGw (K]
| P y: HBuW |
5. update the information of the master database from the database g
KP = as89 + h
Mysql> change master to vc u + 8 K
5LjQ1ql}
-> MASTER_HOST = 'master _ host_name ', // IP address of the master server PMrM2 |
MCdR/vGZ [
-> MASTER_USER = 'replication _ user_name ', // database synchronization User} U {cnd5
A. ^ * "oT \
-> MASTER_PASSWORD = 'replication _ password', // synchronize the database password + * $ c |
]} 3Xyw
-> MASTER_LOG_FILE = 'recorded _ log_file_name ', // file name of the binary log of the master server, the parameter that must be remembered earlier #;?! T },
PPZ6 64 O
-> MASTER_LOG_POS = recorded_log_position; // the start position of the log file (the parameter to be remembered earlier) # & Q ld9 P
(JOIdfr
6. start the slave H from the database! E -? @
G = {E hR2
Mysql> slave start;