Read-Write separation (Read/write splitting).
1. Principle:
Allows the primary database (master) to handle transactional increment, change, delete operations (INSERT, UPDATE, delete), and select query operations from the database (slave).
2. Advantages:
Back up the database, share the database pressure, and withstand greater traffic.
Yii implementation of Read and write separation is very simple, only need to write a few configuration parameters in the configuration file can be implemented.
2.1. Configuring the Db.php File
2.2. Create two databases in order to demonstrate that the IP is pointing to the local MySQL database, but the database name is different, and at the same time inserting a data into the database, the username of the slave database is changed to slave.
2.3. View Query Results
Query for the data with primary key ID 1
Here are the results of the query
Original address: http://www.linuxidc.com/Linux/2015-07/120134.htm
Yii2 for read-write separation (MySQL master-slave database)