MySQL主从配置(5.1版)

节点规划
主MySQL:n13
从MySQL:n14

n13
1.vi /etc/my.cnf
[mysqld]
server-id=1
log-bin=mysql-bin
binlog-do-db=test
binlog-do-db=test1
binlog-ignore-db=mysql
2.service mysqld start
3.mysql -uroot -p123123
mysql> grant replication slave on . to ‘root’@’%’ identified by ‘123123’;
mysql> show master status\G
*************************** 1. row ***************************
File: mysql-bin.000001
Position: 106
Binlog_Do_DB: test,test1
Binlog_Ignore_DB: mysql
4.service mysqld restart

n14
1.service mysqld start
2.vi /etc/my.cnf
[mysqld]
server-id=2
log-bin=mysql-bin
replicate-do-db=test
replicate-do-db=test1
replicate-ignore-db=mysql
3.mysql -uroot -p123123
mysql> slave stop;
mysql> change master to master_host=‘n13’,master_user=‘root’,master_port=3306,master_password=‘123123’,master_log_file=‘mysql-bin.000001’,master_log_pos=106; (注意一定是主节点mysql> show master status\G的File、Position相对应)
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: n13
Master_User: root
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000001
Read_Master_Log_Pos: 106
Relay_Log_File: mysqld-relay-bin.000002
Relay_Log_Pos: 251
Relay_Master_Log_File: mysql-bin.000001
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB: test,test1
Replicate_Ignore_DB: mysql
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: 106
Relay_Log_Space: 407
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
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
1 row in set (0.00 sec)
4.若出现Slave_IO_Running: Yes和Slave_SQL_Running: Yes,说明配置成功

你可能感兴趣的:(MySQL)