我们知道oracle有dataguard实时备份数据,可以做主备切换,而mysql也有自己的一套备库方案,称之为主从复制。
搭建mysql从库是为了实时同步主库数据,同时也可以分担主库的读压力,对数据库端做成读写分离结构。
搭建mysql主从库注意点:
1.主库和从库的 server-id 一定不能相同。
2.在主库创建replication slave账户。
grant replication slave on *.* to identified 'oracle';
3.查看主库master状态
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
关闭slave
设置set globalsql_slave_skip_counter=1;
在开启slave
中国足彩网信息请查看IT技术专栏