手机版
你好,游客 登录 注册 搜索
背景:
阅读新闻

RedHat 5.5 配置 MySQL AB复制

[日期:2012-11-14] 来源:Linux社区  作者:wangxiangtao [字体:大 中 小]

(3) 创建复制用户,并授权由于在测试环境中运用通配符%发生了错误,在生产环境中直接对真实主机名进行授权。

 

MySQL> create user 'replica'@'applinux003.linuxic.com' identified by 'replica';

Query OK, 0 rows affected (0.00 sec)

 

mysql> grant replication slave on *.* to 'replica'@'applinux003.linuxic.com';

Query OK, 0 rows affected (0.00 sec)

 

mysql> grant super on *.* to 'replica'@'applinux00linux003.linuxic.com';

Query OK, 0 rows affected (0.00 sec)

 

mysql> create user 'replica'@'applinux002.linuxic.com' identified by 'replica';

Query OK, 0 rows affected (0.00 sec)

 

mysql> grant replication slave on *.* to 'replica'@'applinux002.linuxic.com';

Query OK, 0 rows affected (0.00 sec)

 

mysql> grant super on *.* to 'replica'@'applinux00linux002.linuxic.com';

Query OK, 0 rows affected (0.00 sec)

(4)锁定数据库状态,读取主服务器二进制日志的状态

 

mysql> flush tables with read lock;

Query OK, 0 rows affected (0.00 sec)

 

mysql> show master status;

+------------------+----------+--------------+------------------+

| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |

+------------------+----------+--------------+------------------+

| mysql-bin.000025 | 1213 | | |

+------------------+----------+--------------+------------------+

1 row in set (0.00 sec)

(5)使用mysqldump创建数据库快照,释放锁

mysql> quit

Bye

[root@applinux002 data]# mysqldump -u root -p --all-database --lock-all-tables > dbdump.db

Enter password:

 

mysql> unlock tables;

Query OK, 0 rows affected (0.00 sec)

 

(6)在从服务器上恢复数据:

[root@applinux003 data]# service mysql status

MySQL running (25059) [ OK ]

[root@applinux003 data]# pwd

/md3200i/data1/mysql/data

[root@applinux003 data]# /usr/local/mysql/bin/mysqladmin -u root -p123456 password 'T4GRUkwMtqIpVzgXA3o6'

[root@applinux003 data]# mysql -u root –p < dbdump.db

Enter password:

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 5

………….

(7)用replica用户做互连测试:

Slave库上

[root@applinux003 data]# mysql -h applinux002.linuxic.com -ureplica -preplica -P8808

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 134

Server version: 5.5.15-log Source distribution

 

Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.

 

Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.

 

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

 

mysql>

 

(8) slave配置

mysql> stop slave;

Query OK, 0 rows affected, 1 warning (0.00 sec)

 

 

mysql> change master to

-> master_host='applinux002.linuxic.com',

-> master_user='replica',

-> master_password='replica',

-> master_port=8808,

-> master_log_file='mysql-bin.000025',

-> master_log_pos=589 ;

Query OK, 0 rows affected (0.02 sec)

--在配置过程中此处多了一个空格导致无法找到log-bin的索引文件,因此一定要仔细,认真…….

mysql> start slave;

mysql> use itao;

Database changed

mysql> select * from test;

+------+

| id |

+------+

| 1 |

| 2 |

| 810 |

+------+

3 rows in set (0.00 sec)

 

mysql> show slave status\G;

*************************** 1. row ***************************

Slave_IO_State: Waiting for master to send event

Master_Host: applinux002.linuxic.com

Master_User: replica

Master_Port: 8808

Connect_Retry: 60

Master_Log_File: mysql-bin.000025

Read_Master_Log_Pos: 1403

Relay_Log_File: applinux003-relay-bin.000002

Relay_Log_Pos: 443

Relay_Master_Log_File: mysql-bin.000025

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: 1403

Relay_Log_Space: 605

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:

Replicate_Ignore_Server_Ids:

Master_Server_Id: 1

1 row in set (0.00 sec)

 

ERROR:

No query specified

---整个复制过程搭建完毕,

(9)进行mysql AB复制测试

Master:

mysql> use itao;

Database changed

mysql> insert into test(id) values (100);

Query OK, 1 row affected (0.01 sec)

 

mysql> insert into test(id) values (200);

Query OK, 1 row affected (0.00 sec)

 

mysql>

 

 

Slave:

mysql> use itao;

Database changed

mysql> select * from test;

+------+

| id |

+------+

| 1 |

| 2 |

| 810 |

| 100 |

+------+

4 rows in set (0.00 sec)

 

mysql> select * from test;

+------+

| id |

+------+

| 1 |

| 2 |

| 810 |

| 100 |

| 200 |

+------+

5 rows in set (0.00 sec)

保持同步,真正实现了读写分离,master库上可以进行读写操作,slave库上用于读操作,可以用于报表,备份,减少了master的压力。

linux
相关资讯       MySQL复制  RedHat 5.5 配置  MySQL AB 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款