Use Yii2 for read/write splitting (MySQL Master/Slave database)

Source: Internet
Author: User

Use Yii2 for read/write splitting (MySQL Master/Slave database)

Read/Write Splitting ).

1. Principle: Let the primary database (master) handle the transaction addition, modification, and deletion operations (INSERT, UPDATE, and DELETE), while the SELECT query operations are processed from the database (slave.

2. Benefits: Back up the database, share the pressure on the database, and withstand more traffic.

Yii is easy to implement read/write splitting. You only need to write several configuration parameters in the configuration file.

1. Configure the db. php file

2. Create two databases. In order to demonstrate that the ip addresses all point to the local MySQL database, but the database names are different, insert a data record in the database, and change the username of the slave database to slave.

3. View query results

Query the data with the primary key id 1.

The query results are as follows:

Yii User Login Mechanism

Introduce js and css files in Yii

Incomplete Yii Solution

Yii CGridView basic usage

Yii framework distributed cache Implementation Scheme

Yii details: click here
Yii: click here

This article permanently updates the link address:

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.