mysql主从同步校验_mysql主从同步设置

本文详细介绍了MySQL主从复制的配置过程,包括主服务器和从服务器的设置步骤,并通过实例展示了如何验证复制效果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1、主服务器地址:192.168.1.244

从服务器地址:192.168.1.245

2、主服务器master设置

1)修改/etc/my.cnf

添加:

log-bin = /home/mysql/log/mysql-bin.log

server-id=244

(注:主从server id不可重复,建议以IP地址设置)

2)登录mysql

创建用户sync并授权192.168.1.245

mysql> GRANT REPLICATION SLAVE ON *.* to 'sync'@'192.168.1.245' identified by ‘password’;

查看主数据库状态

Mysql> show master status;+------------------+----------+--------------+------------------+| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |+------------------+----------+--------------+------------------+| mysql-bin.000005 | 261 | | |+------------------+----------+--------------+------------------+

记录下file与position的值,后面会用到。

3、从服务器设置

1)修改/etc/my.cnf

server-id=245

2)登录mysql

执行同步SQL语句mysql> change master tomaster_host=’192.168.10.130’,master_user=’rep1’,master_password=’password’,master_log_file=’mysql-bin.000005’,master_log_pos=261;

正确执行后启动Slave同步进程mysql> start slave;

主从同步检查mysql> show slave status\G==============================================**************** 1. row *******************Slave_IO_State:Master_Host: 192.168.1.244Master_User: rep1Master_Port: 3306Connect_Retry: 60Master_Log_File: mysql-bin.000005Read_Master_Log_Pos: 415Relay_Log_File: localhost-relay-bin.000008Relay_Log_Pos: 561Relay_Master_Log_File: mysql-bin.000005Slave_IO_Running: YESSlave_SQL_Running: YESReplicate_Do_DB:……………省略若干……………Master_Server_Id: 2441 row in set (0.01 sec)==============================================

至此服务器配置完成。

4、验证主从复制效果

主服务器操作:

mysql> create database first_db;Query Ok, 1 row affected (0.01 sec)

在主服务器上创建表first_tbmysql> create table first_tb(id int(3),name char(10));Query Ok, 1 row affected (0.00 sec)

在主服务器上的表first_tb中插入记录mysql> insert into first_tb values (001,’myself’);Query Ok, 1 row affected (0.00 sec)

在从服务器上查看mysql> show databases;=============================+--------------------+| Database |+--------------------+| information_schema || first_db || mysql || performance_schema || test |+--------------------+5 rows in set (0.01 sec)=============================数据库first_db已经自动生成

mysql> use first_dbDatabase chaged

mysql> show tables;=============================+--------------------+| Tables_in_first_db |+--------------------+| first_tb |+--------------------+1 row in set (0.02 sec)=============================数据库表first_tb也已经自动创建

mysql> select * from first_tb;=============================+------+------+| id | name |+------+------+| 1 | myself |+------+------+1 rows in set (0.00 sec)=============================记录也已经存在

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值