配置部分
=====================================
主机配置:
log-bin=mysql-bin
server-id=83306//配置id 在此用端口号
从机配置:
log-bin=mysql-bin
server-id=83307//配置id 在此用端口号
重启主机
重启从机
主机执行:
GRANT REPLICATION SLAVE ON *.* to 'mysync'@'%' identified by 'mysync';
为从机同步分配专用账户
主机执行:
mysql> show master status\G
*************************** 1. row ***************************
File: mysql-bin.000004【从机配置要用】
Position: 455 【从机配置要用】
Binlog_Do_DB:
Binlog_Ignore_DB:
1 row in set (0.00 sec)
从机执行:
mysql> change master to master_host='127.0.0.1',master_port=83306,master_user='mysync',master_password='mysync', master_log_file='mysql-bin.000004',master_log_pos=455;
mysql> start slave;
mysql> show slave status\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 127.0.0.1
Master_User: mysync
Master_Port: 83306
Connect_Retry: 60
Master_Log_File: mysql-bin.000004
Read_Master_Log_Pos: 455
Relay_Log_File: mysqld-db83307-relay-bin.000002
Relay_Log_Pos: 456
Relay_Master_Log_File: mysql-bin.000004
==========================================================
测试
主机执行:
create database td;
use td;
create table tb(`id` int(11),`nick` char(10));
insert into tb values(1,'hello');
从机执行:
select * from td.tb;