我們知道oracle有dataguard實時備份數(shù)據(jù),可以做主備切換,而mysql也有自己的一套備庫方案,稱之為主從復制。
搭建mysql從庫是為了實時同步主庫數(shù)據(jù),同時也可以分擔主庫的讀壓力,對數(shù)據(jù)庫端做成讀寫分離結(jié)構(gòu)。
搭建mysql主從庫注意點:
1.主庫和從庫的 server-id 一定不能相同。
2.在主庫創(chuàng)建replication slave賬戶。
grant replication slave on *.* to identified 'oracle';
3.查看主庫master狀態(tài)
mysql> show master status /g
*************************** 1. row ***************************
file: mysql-bin.000005
position: 251651
binlog_do_db:
binlog_ignore_db:
1 row in set (0.00 sec)
4.配置從庫
change master to
-> master_host='192.168.0.232',
-> master_user='repl',
-> master_password='oracle',
-> master_log_file='mysql-bin.000005',
-> master_log_pos=251651;
5. 啟動從庫
slave start
show slave status/g
*************************** 1. row ***************************
slave_io_state: waiting for master to send event
master_host: ***********
master_user: repl
master_port: 3306
connect_retry: 60
master_log_file: mysql-bin.000005
read_master_log_pos: 463725968
relay_log_file: mysql-relay-bin.000006
relay_log_pos: 463726114
relay_master_log_file: mysql-bin.000005
slave_io_running: yes
slave_sql_running: yes
replicate_do_db: ******************
replicate_ignore_db:
replicate_do_table:
replicate_ignore_table:
replicate_wild_do_table:
replicate_wild_ignore_table:
last_errno: 0
last_error:
skip_counter: 0
exec_master_log_pos: 463725968
relay_log_space: 873569451
until_condition: none
until_log_file:
until_log_pos: 0
master_ssl_allowed: no
master_ssl_ca_file:
master_ssl_ca_path:
master_ssl_cert:
master_ssl_cipher:
master_ssl_key:
seconds_behind_master: 0
master_ssl_verify_server_cert: no
last_io_errno: 0
last_io_error:
last_sql_errno: 0
last_sql_error:
replicate_ignore_server_ids:
master_server_id: 100
注意:
如果從庫slave_io_running: no/ slave_sql_running: no
關(guān)閉slave
設(shè)置set globalsql_slave_skip_counter=1;
在開啟slave
更多信息請查看IT技術(shù)專欄