Home > Database > Mysql Tutorial > MySQL复制和性能优化

MySQL复制和性能优化

WBOY
Release: 2016-06-07 17:01:29
Original
1036 people have browsed it

复制(Replication):通过复制执行过的语句或者数据集从主服务器上复制到一个或多个从服务器上实现多个数据库服务器之间数据库的

复制(Replication):通过复制执行过的语句或者数据集从主服务器上复制到一个或多个从服务器上实现多个数据库服务器之间数据库的同步。

MySQL's built-in replication capability is the foundation for building large, highperformance applications on top of MySQL.

MySQL supports two kinds of replication: statement-based replication(基于语句的复制) and row-based replication(基于行的复制).

Statement-based (or "logical") replication has been available since MySQL 3.23, and it's what most people are using in production today

Row-based replication is new in MySQL 5.1.

Both kinds work by recording changes in the master's binary log and replaying the log on the slave

基于语句的复制:记录改变数据库的语句,,将语句在从服务器上在执行一遍,效率较高。

基于行的复制:将语句执行后的结果包括行的改变或者添加整个复制到从服务器中去。

混合方式的复制:由MySQL自动来判断。

复制过程:

MySQL

主服务器上线程:mysql dump

从服务器两个线程:I/O thread ,SQL thread。

过程:从服务器的I/O 线程(主服务器的远程客户端)不断尝试连接主服务器,读取其二进制日志,主服务器收到请求后将检查自己的Binary Log并根据从服务器发来的Relay Log的相关信息来确认自从上次复制之后主服务器内容是否有更新,如果有,则主服务器启动mysql dump线程,将对方所请求的数据返回给从服务器,从服务器收到数据后会将数据保存在Relay Log。SQL thread 会不定期的读取Relay Log,如果发现有更新,则读取更新的语句或者行将其保存在从服务器上。

MySQL解决的问题:数据备份、负载均衡、高可用、数据分布(异地容灾)、升级测试。

下面我们来实现基于MySQL主从复制的架构:

Master:192.168.1.11  MySQL已安装完毕

[root@station39 ~]# vim /etc/my.cnf

log-bin=master-bin     //** update  line 50

log-bin-index=master-bin.index  //** add line 51

server-id       = 1           //** line 59

linux

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