我們知道oracle有dataguard實(shí)時(shí)備份數(shù)據(jù),可以做主備切換,而mysql也有自己的一套備庫(kù)方案,稱之為主從復(fù)制。
搭建mysql從庫(kù)是為了實(shí)時(shí)同步主庫(kù)數(shù)據(jù),同時(shí)也可以分擔(dān)主庫(kù)的讀壓力,對(duì)數(shù)據(jù)庫(kù)端做成讀寫(xiě)分離結(jié)構(gòu)。
搭建mysql主從庫(kù)注意點(diǎn):
1.主庫(kù)和從庫(kù)的 server-id 一定不能相同。
2.在主庫(kù)創(chuàng)建replication slave賬戶。
grant replication slave on *.* to identified 'oracle';
3.查看主庫(kù)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.配置從庫(kù)
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. 啟動(dòng)從庫(kù)
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
注意:
如果從庫(kù)slave_io_running: no/ slave_sql_running: no
關(guān)閉slave
設(shè)置set globalsql_slave_skip_counter=1;
在開(kāi)啟slave
更多信息請(qǐng)查看IT技術(shù)專欄