Home > Database > Mysql Tutorial > 《高可用MySQL》 — 主从复制_MySQL

《高可用MySQL》 — 主从复制_MySQL

WBOY
Release: 2016-06-01 13:38:47
Original
1003 people have browsed it

bitsCN.com

《高可用MySQL》P10

MySQL主从复制

 

MySQL的复制在以下环境中经常使用:

1 通过热备份来避免灾难

2 产生报表

使用从服务器来产生报表,可大大降低主服务器的负载。

3 调试和审计

例如,查看某些查询是否有性能问题,以及服务器是否由于某个槽糕的查询而不同步。

 

MySQL复制的基本步骤

1 配置一个服务器作为 Master。

2 配置一个服务器作为 Slave。

3 将 Slave 连接到 Master。

除非你从一开始就计划复制且 my.conf 文件中配置正确,否则步骤1和步骤2要求必须重启每个服务器。

 

配置Master

将配置选项添加到my.conf以配置Master

[mysqld]user          = mysqlpid-file      = /var/run/mysqld/mysqld.pidsocket        = /var/run/mysqld/mysqld.sockport          = 3306basedir       = /usrdatadir       = /var/lib/mysqltmpdir        = /tmp<strong>log</strong><strong>-bin       = master-binlog-bin-index = master-bin.indexserver-id     = 1</strong>
Copy after login

 在Master上创建一个复制用户

master> CREATE USER repl_user;Query OK, 0 rows affected (0.00 sec)master> GRANT REPLICATION SLAVE on *.* to repl_user IDENTIFIED by 'xyzzy';Query OK, 0 rows affected (0.00 sec)
Copy after login

 

配置Slave

添加选项到my.conf文件来配置Slave

[mysqld]user                = mysqlpid-file            = /var/run/mysqld/mysqld.pidsocket              = /var/run/mysqld/mysqld.sockport                =  3306basedir             =  /usrdatadir             =  /var/lib/mysqltmpdir              =  /tmp<strong>server</strong><strong>-id           = 2relay-log-index     = slave-relay-bin.indexrelay-log           = slave-relay-bin</strong>
Copy after login

 

连接Master和Slave

  slave>  CHANGE MASTER TO      ->     MASTER_HOST  ="master-1",      ->     MASTER_PORT = 3306,      ->     MCSTER_USER = 'repl_user',      ->     MAST_PASSWORD = 'xyzzy';  Query OK, 0 rows affected(0.00 sec)  slave> START SLAVE;
Copy after login

 

bitsCN.com
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template