/ 中存储网

MySQL 5.6数据库配置主从同步

2014-07-13 15:50:13 来源:中存储网

win7环境下mysql主从搭建

我下载的是压缩包,免安装的那种

1、简单安装

解压后把my-default.ini复制一份改为my.ini默认mysql会找这个文件,首先从system32下找,然后在安装目录找

basedir = D:/soft_install/Java/mysql_slave_one
datadir = D:/soft_install/Java/mysql_slave_one/data
port = 3307
server_id = 2

只需要配置这几个东西就可以了

然后将mysql安装成服务

mysqld.exe --install MySql_master --defaults-file=D:/soft_install/Java/mysql_slave/my.ini

就可以将mysql安装成服务

2、主服务器配置

log_bin = mysql_bin
binlog_format = ROW
binlog_cache_size = 4M
max_binlog_size = 1G
max_binlog_cache_size = 128M
binlog-do-db = test
binlog-ignore-db=mysql
skip-log-warnings=yes
expire_logs_days=1

# These are commonly set, remove the # and set as required.
basedir = D:/soft_install/Java/mysql_master
datadir = D:/soft_install/Java/mysql_master/data
port = 3306
server_id = 1

进入服务器,授权同步用户

GRANT REPLICATION SLAVE ON *.* TO 'test_user'@'127.0.0.1'   identified by '123456';

3、从服务器配置

log_bin=mysql_bin
relay-log=relay_log
replicate-ignore-db=mysql 
replicate-do-db=test

# These are commonly set, remove the # and set as required.
basedir = D:/soft_install/Java/mysql_slave_one
datadir = D:/soft_install/Java/mysql_slave_one/data
port = 3307
server_id = 2

4、启动时先启动主服务器,然后启动从服务器

进入从服务器,运行以下命令

change master to master_host='127.0.0.1',master_user='test_user',master_password='123456',
 master_log_file='mysql-bin.000015',master_log_pos=120;

start slave

其中的 'mysql-bin.000015',120 是需要进如主服务器运行 show master status来查看才能知道的