Yii2 implements read-write separation (MySQL master-slave database), yii2mysql_PHP tutorial

WBOY
Release: 2016-07-12 09:04:18
Original
1024 people have browsed it

Yii2 implements read/write separation (MySQL master-slave database), yii2mysql

read/write splitting (Read/Write Splitting).

1. Principle:

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

2. Advantages:

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

It is very simple to realize the separation of reading and writing in yii. You only need to write a few configuration parameters in the configuration file to achieve it.

2.1. Configure db.php file

2.2. Create two databases to demonstrate that both IPs point to the local MySQL database, but the database names are different. At the same time, insert a piece of data into the database and change the username of the slave database to slave.

2.3. View query results

Query the data whose primary key id is 1

The following are the query results

Original address: http://www.linuxidc.com/Linux/2015-07/120134.htm

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1073812.htmlTechArticleYii2 implements read/write separation (MySQL master-slave database), yii2mysql read/write splitting (Read/Write Splitting). 1. Principle: Let the master database (master) handle transactional add, modify, and delete operations (...
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