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: