环境
Mysql 5.7、windows主[192.167.19]、windows从[192.168.1.18]
一、主库配置 1、打开主库my.ini,编辑配置如下内容:
[mysql]
default-character-set=utf8
[mysqld]
port = 3306
basedir=D:\mysql5
datadir=D:\mysql5\data
max_connections=1000
character-set-server=utf8
default-storage-engine=INNODB
default-time_zone = '+8:00'
log-bin = mysql-bin
server-id = 19
binlog-do-db=test_db
binlog-ignore-db=mysql
binlog-ignore-db=information_schema
binlog-ignore-db=performance_schema
2、主库bin目录,登录主库:
C:\soft\mysql5\bin> mysql -u root -p
3、授权主从复制专用账号
mysql> GRANT REPLICATION SLAVE ON *.* TO 'db_sync'@'%' IDENTIFIED BY 'db_sync';
4、刷新权限
msyql> flush privileges;
5、查看主库信息,记录下文件名和点位
msyql> show master status;
注意:记录一下file和Position
二、从库配置 1、打开从库my.ini,编辑配置如下内容:
[mysql]
default-character-set=utf8
[mysqld]
port = 3306
basedir=D:\mysql5
datadir=D:\mysql5\data
max_connections=200
character-set-server=utf8
default-storage-engine=INNODB
default-time_zone = '+8:00'
log-bin = mysql-bin
server-id = 18
replicate_wild_do_table=test_db.%
replicate_wild_ignore_table=mysql.%
replicate_wild_ignore_table=information_schema.%
replicate_wild_ignore_table=performance_schema.%
2、从库bin目录,登录:
C:\soft\mysql5\bin> mysql -u root -p
3、根据主库信息,更改语句[file信息、Position信息] 、执行。
mysql> CHANGE MASTER TO MASTER_HOST='主库ip',MASTER_PORT=3306,MASTER_USER='db_sync', MASTER_PASSWORD='db_sync',MASTER_LOG_FILE='file信息',MASTER_LOG_POS=Position信息;
4、启动服务
mysql> start slave
mysql> stop slave
mysql> reset slave
5、确认Slave_IO_Runing以及Slave_SQL_Runing两个状态位是否为“Yes”,如果不为 Yes, 请检查error_log,然后排查相关异常。
mysql>show slave status\G
|