[mysqld] log-bin=mysql-bin //必须启用二进制日志 server-id=1 //必须是服务器唯一id,默认是0,
[mysqld] #log-bin=mysql-bin // 从服务器的二进制日志非必须启用,然而如果该从服务器要作为其他服务器的主服务器时则需要启用;若启用二进制日志,可以用作数据备份和功能恢复 server-id=2 //必须服务器唯一ID, 默认是0,不要与服务器一样
mysql> CREATE USER 'repl'@'192.168.1.103' IDENTIFIED BY 'slavepass'; mysql> GRANT REPLICATION SLAVE ON *.* TO 'repl'@'192.168.1.103';
mysql> FLUSH TABLES WITH READ LOCK; ( 要解锁退出该会话即可 )
mysql > SHOW MASTER STATUS; +------------------+----------+--------------+------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | +------------------+----------+--------------+------------------+ | mysql-bin.000003 | 107 | | | +------------------+----------+--------------+------------------+ 记下二进制文件名:mysql-bin.000003和位置107
shell> mysqldump --all-databases --lock-all-tables >dbdump.db
mysql> UNLOCK TABLES; (另:关闭连接也可以解锁)
mysql > stop slave;
mysql > create databases 'dataname'; mysql > use 'dataname'; mysql > source dbdump.db;
mysql> CHANGE MASTER TO
-> MASTER_HOST='192.168.1.103',
-> MASTER_USER='repl',
-> MASTER_PASSWORD='slavepass',
-> MASTER_LOG_FILE='mysql-bin.000003',
-> MASTER_LOG_POS=107
注:执行该语句之前必须确保没有slave线程运行,否则报错
mysql > start slave;