主从版本一致
master端
[root@puppetmaster ~]# cat /etc/my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
log-bin = mysql-bin //[必须]启用二进制日志
server-id=1 //[必须]服务器唯一ID,默认是1,
# Default to using old password format for compatibility with mysql3.x
# clients (those using the mysqlclient10 compatibilitypackage).
old_passwords=1

# Disabling symbolic-links is recommended to prevent assortedsecurity risks;
# to do so, uncomment this line:
# symbolic-links=0

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid


授权(在主服务器上进行) GRANT REPLICATION SLAVE ON *.* to'slave1'@'192.168.188.143identified by '123456';
mysql>flush privileges;

mysql>flush tables with read lock;

将从库的database导入 mysql -u root -p dashboard </home/dashboard.sql(必须有dashboard库 如没有则创建 created databasedashboard;)

主库 mysql 解锁
mysql>unlock tables;

mysql> show master status;
+------------------+----------+--------------+------------------+
|File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000002| 373| | |
+------------------+----------+--------------+------------------+
1 row in set (0.00 sec)


配置从服务器 mysql> change master tomaster_host='192.168.188.151', master_user='slave1',master_password='123456', master_log_file='mysql-bin.000002',master_log_pos=373;

从服务器上my.cnf
也启动二进制日志
[root@logserver-SW ~]# cat /etc/my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
server-id = 2
# Default to using old password format for compatibility with mysql3.x
# clients (those using the mysqlclient10 compatibilitypackage).
old_passwords=1

# Disabling symbolic-links is recommended to prevent assortedsecurity risks;
# to do so, uncomment this line:
# symbolic-links=0

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

正确执行后再执行: mysql> startslave;


mysql> show slave status\G

mysql> show slave status\G;
*************************** 1. row***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.188.151
Master_User: slave1
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000002
Read_Master_Log_Pos: 373
Relay_Log_File: mysqld-relay-bin.000004
Relay_Log_Pos: 510
Relay_Master_Log_File: mysql-bin.000002
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: 373
Relay_Log_Space: 510
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 0
1 row in set (0.00 sec)


这两个必须为YES
Slave_IO_Running: Yes
Slave_SQL_Running: Yes