Home > Backend Development > PHP Tutorial > Yii2 implements read-write separation (MySQL master-slave database)

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

WBOY
Release: 2016-07-29 09:11:30
Original
1051 people have browsed it

Read/Write Splitting.

1. Principle:

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

2. Advantages:

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

 Yii is very simple to implement read and write separation. You only need to write a few configuration parameters in the configuration file.

2.1. Configure the db.php file

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

2.2. Create two databases. In order to demonstrate, the IP addresses both point to the local MySQL database, but the database names are different. At the same time, insert a piece of data in the database respectively, and change the username of the slave database to slave.

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

2.3. View the query results

Query the data with the primary key id 1

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

The following are the query results

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

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

The above introduces the implementation of read-write separation (MySQL master-slave database) in Yii2, including the relevant aspects. I hope it will be helpful to friends who are interested in PHP tutorials.

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