概述
在一台linux服务器上实现MySQL Replication
配置说明:
master:
version 5.1.47
/etc/my47.cnf
server-id = 1
port = 3307
socket = /tmp/mysql47.sock
datadir = /mysql47/data
binlog-do-db = test(复制库名)
master:
version 5.1.47
/etc/my47.cnf
server-id = 1
port = 3307
socket = /tmp/mysql47.sock
datadir = /mysql47/data
binlog-do-db = test(复制库名)
slave:
version 5.1.48
/etc/my48.cnf
server-id = 2
port = 3306
socket = /tmp/mysql48.sock
datadir = /usr/local/mysql/var
replicate-do-db = test(与master的binlog-do-db二选一即可)
version 5.1.48
/etc/my48.cnf
server-id = 2
port = 3306
socket = /tmp/mysql48.sock
datadir = /usr/local/mysql/var
replicate-do-db = test(与master的binlog-do-db二选一即可)
1.在master上创建复制用户
$ mysqld_safe --defaults-file=/etc/my47.cnf &
$ mysql -S /tmp/mysql47.sock -p
mysql> create user rep@localhost identified by 'rep';
$ mysqld_safe --defaults-file=/etc/my47.cnf &
$ mysql -S /tmp/mysql47.sock -p
mysql> create user rep@localhost identified by 'rep';
mysql> GRANT replication slave ON *.* to
'rep'@'localhost';
2.分别配置master和slave的my.cnf参数
master:
# vi /etc/my47.cnf
[mysqld]
server-id = 1
socket = /tmp/mysql47.sock
port = 3307
datadir = /mysql47/data
log-bin=mysql-bin
#binlog-do-db = test
master:
# vi /etc/my47.cnf
[mysqld]
server-id = 1
socket = /tmp/mysql47.sock
port = 3307
datadir = /mysql47/data
log-bin=mysql-bin
#binlog-do-db = test
slave:
# vi /etc/my48.cnf
[mysqld]
server-id = 2
port = 3306
socket = /tmp/mysql48.sock
#log-bin=mysql-bin
#log-slave-updates
#read-only=1
replicate-do-db=test
# vi /etc/my48.cnf
[mysqld]
server-id = 2
port = 3306
socket = /tmp/mysql48.sock
#log-bin=mysql-bin
#log-slave-updates
#read-only=1
replicate-do-db=test
3.slave上配置master信息
execute the following statement on the slave:
$ mysqld_safe --defaults-file=/etc/my48.cnf &
$ mysql -S /tmp/mysql48.sock -p
mysql> CHANGE MASTER TO
-> MASTER_HOST='localhost',
-> MASTER_PORT=3307,
-> MASTER_USER='rep',(前面创建具有复制权限的那个用户)
-> MASTER_PASSWORD='rep',
-> MASTER_LOG_FILE='mysql-bin.000014',
-> MASTER_LOG_POS=106;
其中MASTER_LOG_FILE='mysql-bin.000014',MASTER_LOG_POS=106参数出自master
master执行:
mysql> show master status;
+------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000014 | 106 | | |
+------------------+----------+--------------+------------------+
execute the following statement on the slave:
$ mysqld_safe --defaults-file=/etc/my48.cnf &
$ mysql -S /tmp/mysql48.sock -p
mysql> CHANGE MASTER TO
-> MASTER_HOST='localhost',
-> MASTER_PORT=3307,
-> MASTER_USER='rep',(前面创建具有复制权限的那个用户)
-> MASTER_PASSWORD='rep',
-> MASTER_LOG_FILE='mysql-bin.000014',
-> MASTER_LOG_POS=106;
其中MASTER_LOG_FILE='mysql-bin.000014',MASTER_LOG_POS=106参数出自master
master执行:
mysql> show master status;
+------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000014 | 106 | | |
+------------------+----------+--------------+------------------+
查看slave状态:
mysql> slave start;
mysql> show slave statusG;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: localhost
Master_User: rep
Master_Port: 3307
Connect_Retry: 60
Master_Log_File: mysql-bin.000017
Read_Master_Log_Pos: 193
Relay_Log_File: oel5-relay-bin.000013
Relay_Log_Pos: 338
Relay_Master_Log_File: mysql-bin.000017
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB: test
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: 193
Relay_Log_Space: 637
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:
Slave_IO_Running、Slave_SQL_Running状态为YES
mysql> slave start;
mysql> show slave statusG;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: localhost
Master_User: rep
Master_Port: 3307
Connect_Retry: 60
Master_Log_File: mysql-bin.000017
Read_Master_Log_Pos: 193
Relay_Log_File: oel5-relay-bin.000013
Relay_Log_Pos: 338
Relay_Master_Log_File: mysql-bin.000017
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB: test
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: 193
Relay_Log_Space: 637
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:
Slave_IO_Running、Slave_SQL_Running状态为YES
mysql> show processlistG;
查看复制进程
查看复制进程
4.Replication验证
master:
mysql> use test;
mysql> create table t (i int);
mysql> insert into t values(10);
mysql> insert into t values(20);
mysql> select * from t;
+------+
| i |
+------+
| 10 |
| 20 |
+------+
master:
mysql> use test;
mysql> create table t (i int);
mysql> insert into t values(10);
mysql> insert into t values(20);
mysql> select * from t;
+------+
| i |
+------+
| 10 |
| 20 |
+------+
slave:
mysql> use test;
mysql> select * from t;
+------+
| i |
+------+
| 10 |
| 20 |
+------+
mysql> use test;
mysql> select * from t;
+------+
| i |
+------+
| 10 |
| 20 |
+------+
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/17997/viewspace-668384/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/17997/viewspace-668384/
最后
以上就是整齐黄豆为你收集整理的MySQL Replication Configuration的全部内容,希望文章能够帮你解决MySQL Replication Configuration所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复