================================Start 安装环境 Start================================

+------------------------------------+
1.安装环境
+------------------------------------+
主(Master):
eth0-IP :192.168.8.11
数据库名:test
端口    :3306
从(Slave) :
eth0-IP :192.168.8.12
数据库名:test (主从数据库名最好一致,便于管理和访问)
端口    :3306
主从数据库版本需保持一致
================================End 安装环境 End================================
================================Start 主(Master)配置 Start================================
+------------------------------------+
1.创建可以复制的用户账号,数据库命令行中输入如下的命令
+------------------------------------+
GRANT REPLICATION SLAVE ON *.* TO 'user_sync'@'%' IDENTIFIED BY '123456';
+------------------------------------+
2.编辑my.cnf
+------------------------------------+
vi /lamp/mysql/3306/my.cnf
my.cnf修改以下内容:
+------------
server-id = 1001
binlog-do-db = test
log-bin = mysql-bin
------------+
+------------------------------------+
3.启动MySQL数据库
+------------------------------------+
+------------------------------------+
4.得到binlog日志文件名和偏移量,数据库命令行中输入如下的命令
+------------------------------------+
SHOW MASTER STATUS; 或 SHOW MASTER STATUS\G;
+------------------+----------+--------------+------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000001 |      106 | test         |                  |
+------------------+----------+--------------+------------------+
================================End 主(Master)配置 End================================
================================Start 从(Slave)配置 Start================================
+------------------------------------+
1.编辑my.cnf
+------------------------------------+
vi /lnmp/mysql/3306/my.cnf
my.cnf修改以下内容:
+------------
server-id=1002
------------+
+------------------------------------+
2.启动SLAVE服务,数据库命令行中输入如下的命令
+------------------------------------+
CHANGE MASTER TO MASTER_HOST='192.168.8.11', MASTER_PORT=3306, MASTER_USER='user_sync', MASTER_PASSWORD='123456', MASTER_LOG_FILE='mysql-bin.000001', MASTER_LOG_POS=106;
+------------------------------------+
3.启动从服务器SLAVE线程,数据库命令行中输入如下的命令
+------------------------------------+
START SLAVE;
+------------------------------------+
4.显示进程,数据库命令行中输入如下的命令
+------------------------------------+
SHOW PROCESSLIST\G;
Info: NULL 表示slave已经连接上master,开始接受并执行日志
+------------------------------------+
5.查看slave线程状态,数据库命令行中输入如下的命令
+------------------------------------+
SHOW SLAVE STATUS; 或 SHOW SLAVE STATUS\G;
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
如以上二行同时为Yes,说明配置成功
+------------------------------------+
6.其他命令
+------------------------------------+
Slave start; --启动复制线程
Slave stop; --停止复制线程
Reset slave; --重置复制线程
Show slave status; --显示复制线程的状态
Change master to; --动态改变到主数据库的配置
================================End 从(Slave)配置 End================================