1、主服务器192.168.1.95
从服务器 192.168.1.96
2、
主服务器my.cnf
server-id=1
log-bin=mysql-bin
从服务器my.cnf
server-id=1
log-bin=mysql-bin
3、主服务器
配置用户复制权限
GRANT REPLICATION SLAVE ON *.* TO 'cactiuser'@'192.168.1.95' IDENTIFIED BY '123456';
show master status;
+------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000035 | 2422836 | cactidb | mysql |
+------------------+----------+--------------+------------------+
1 row in set (0.00 sec)
4、从服务器
mysql> CHANGE MASTER TO
-> MASTER_HOST='192.168.1.95',
-> MASTER_USER='cactiuser',
-> MASTER_PASSWORD='123456',
-> MASTER_LOG_FILE='mysql-bin.000035',
-> MASTER_LOG_POS=2422836;
slave start;
show slave status\G;
mysql> show slave status\G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.1.95
Master_User: cactiuser
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000035
Read_Master_Log_Pos: 2486083
Relay_Log_File: mysql2-relay-bin.000002
Relay_Log_Pos: 63500
Relay_Master_Log_File: mysql-bin.000035
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 2486083
5.测试
测试语句
create table name(id int(4),name varchar(20));
insert into name(id,name) values(1,peter);
主服务器
mysql> select * from name;
+------+-------+
| id | name |
+------+-------+
| 1 | peter |
+------+-------+
1 row in set (0.00 sec)
从服务器
mysql> select * from name;
+------+-------+
| id | name |
+------+-------+
| 1 | peter |
+------+-------+
PS,是不是很有趣,很简单;