mysql主从同步配置超详细_mysql主从同步配置(超详细)_MySQL

bitsCN.com

0.首先在准备两个机器A,B,在上面安装相同版本的mysql(最好是5.0以上)

A为主数据库,B为从数据库

1 mysql同步server-id 格式说明

A B C

A:1:表示域名配置

2:表示SDNS服务器

3:表示探测中心服务器

4:表示收集中心服务器

5:表示探测运算中心服务器

6:表示探测节点服务器

一般

功能模块ID小的为master服务器

功能模块ID大的为slave服务器

B: 一般在同一个局域网内为一组

C:同一功能模块分组内的服务器ID在同一分组内同一个功能模块各个的ID号

例如:3 03 01

2 主从同步配置(主)

1) 修改my.cnf

在my.cnf 中[mysqld] 字段中添加

vi /etc/my.cnf

server-id=10101

log-bin=mysql-bin #这个一定得设置,否则没有日志的话,从数据库上会报错

binlog-ignore-db=mysql,test

innodb_flush_log_at_trx_commit=1

sync_binlog=1

log-slave-updates

2) 重启mysql

service mysql restart

3) 添加帐户给主服务器上mysql的从机用

GRANT REPLICATION SLAVE ON *.* TO 'repl'@'2.2.2.%' IDENTIFIED BY 'testpass';

4) 创建数据库

>create database gslb;

>create database dns;

5) 显示日志位置

>SHOW MASTER STATUS;

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

| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |

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

| mysql-bin.000003 | 107 | | |

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

3 主从同步配置(从)

1) 修改my.cnf

在my.cnf 中[mysqld] 字段中添加

vi /etc/my.cnf

server-id = 20101

replicate-do-db = dns

replicate-do-table = gslb.zone

replicate-do-table = gslb.zone_rr

master-info-file = master.info

relay-log = relay-relay-bin

relay-log-index = relay-relay-bin.index

relay-log-info-file=relay-relay-log.info

2) 重启mysql

service mysql restart

3) 设置主服务器信息

change master to master_host='1.1.1.1',

master_user='repl',

master_password='testpass',

master_log_file='mysql-bin.000003',

master_log_pos=107;

4) 启动同步

>start slave;

5) 显示日志位置,出现两个Yes就表示同步成功

mysql> show slave status /G;

*************************** 1. row ***************************

Slave_IO_State: Waiting for master to send event

Master_Host: 1.1.1.1

Master_User: repl

Master_Port: 3306

Connect_Retry: 60

Master_Log_File: mysql-bin.000006

Read_Master_Log_Pos: 270500590

Relay_Log_File: relay-relay-bin.000012

Relay_Log_Pos: 1148354

Relay_Master_Log_File: mysql-bin.000006

Slave_IO_Running: Yes

Slave_SQL_Running: Yes

Replicate_Do_DB:

Replicate_Ignore_DB:

Replicate_Do_Table: gslb.server_threshold,gslb.server,gslb.threshold,gslb.vip,gslb.status,gslb.vip_threshold

Replicate_Ignore_Table:

Replicate_Wild_Do_Table:

Replicate_Wild_Ignore_Table:

Last_Errno: 0

Last_Error:

Skip_Counter: 0

Exec_Master_Log_Pos: 270500590

Relay_Log_Space: 1148510

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: 10201

1 row in set (0.00 sec)

6) 导入master的数据

mysql –e “create database gslb”

mysql gslb < gslb.sql

mysql –e ”create database dns”

mysql dns < dns.sql

本文出自 “一方有” 博客bitsCN.com

f68f2add0b68e4f9810432fce46917b7.png

本文原创发布php中文网,转载请注明出处,感谢您的尊重!

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值