Home > php教程 > php手册 > Yii2实现读写分离(MySQL主从数据库),yii2mysql

Yii2实现读写分离(MySQL主从数据库),yii2mysql

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-13 08:50:30
Original
1217 people have browsed it

Yii2实现读写分离(MySQL主从数据库),yii2mysql

读写分离(Read/Write Splitting)。

1.原理:

让主数据库(master)处理事务性增、改、删操作(INSERT、UPDATE、DELETE),而从数据库(slave)处理SELECT查询操作。
Copy after login

2.优点:

备份数据库,分担数据库压力,承受更大的访问量。
Copy after login

 

  yii实现读写分离非常简单,只需要在配置文件中写几个配置参数即可实现。

2.1.配置db.php文件

  

2.2.创建两个数据库为了演示ip都指向本地的MySQL数据库,但是数据库名称不同,同时在数据库分别插入一条数据,将slave数据库的username改成slave。

2.3.查看查询结果

查询主键id为1的那条数据

以下是查询结果

 

原文地址:http://www.linuxidc.com/Linux/2015-07/120134.htm

 

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
Latest Issues
yii2 error connecting to mongodb3.2.4
From 1970-01-01 08:00:00
0
0
0
How to use mongodb to do rbac in yii2
From 1970-01-01 08:00:00
0
0
0
php - yii2-ueditor-widget
From 1970-01-01 08:00:00
0
0
0
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template