温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

mysql中怎么配置主从同步

发布时间:2021-08-04 17:01:14 来源:亿速云 阅读:89 作者:Leah 栏目:数据库

今天就跟大家聊聊有关mysql中怎么配置主从同步,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。

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  IDENTIFIED BY 'testpass';
 
4)        创建
>create database gslb;
>create database dns;
5)        显示日志位置
>SHOW MASTER STATUS;
+------------------+-----------+--------------+------------------+
| File             | Position  | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+-----------+--------------+------------------+
| -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 &ndash;e ”create database dns”
mysql dns < dns.sql

看完上述内容,你们对mysql中怎么配置主从同步有进一步的了解吗?如果还想了解更多知识或者相关内容,请关注亿速云行业资讯频道,感谢大家的支持。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI