在windows 7系统上安装mysql5.6,
主库:
安装目录为:D:\Program Files\MySQL\MySQL Server 5.6
从库:
对安装目录进行拷贝,重命名:D:\Program Files\MySQL\MySQL Server 5.6x
主库my.ini配置文件:
[mysqld]
port=3306
character-set-server=utf8
basedir=D:/Program Files/MySQL/MySQL Server 5.6
datadir=D:/Program Files/MySQL/MySQL Server 5.6/data
sql-mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
# 主从复制相关
server-id=1
binlog-do-db=db_zhang
binlog-ignore-db=mysql
binlog-ignore-db=information_schema
log-bin=mysql-bin
从库my.ini配置文件:
[mysqld]
port=3307
character_set_server=utf8
basedir=D:/Program Files/MySQL/MySQL Server 5.6x
datadir=D:/Program Files/MySQL/MySQL Server 5.6x/data
sql-mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
#主从复制相关
server-id=2
replicate-do-db=db_zhang
replicate-ignore-db=mysql
replicate-ignore-db=information_schema
log-bin=mysql-bin
0. 为主库建立repl用户,专门用于主从复制
CREATE USER 'repl'@'127.0.0.1' IDENTIFIED BY 'slavepass';
GRANT REPLICATION SLAVE ON *.* TO 'repl'@'127.0.0.1';
1. 启动主服务器
使用mysql客户端连接服务器:show master status \G;
其中的file和position要在从库中配置。
2. 启动从服务器
使用mysql客户端连接服务器,依次输入下列命令。
1) stop slave;
2) CHANGE MASTER TO
MASTER_HOST='127.0.0.1',
MASTER_USER='repl',
MASTER_PASSWORD='slavepass',
MASTER_PORT=3306,
MASTER_LOG_FILE='mysql-bin.000001',
MASTER_LOG_POS=1717,
MASTER_CONNECT_RETRY=10;
3) start slave;
4) show slave status \G;
这是因为从库是直接从主库的目录拷贝过来的。
修改 D:\Program Files\MySQL\MySQL Server 5.6x\data\auto.cnf 中server-uuid的值
重启从库完成!