Read/Write Splitting.
1. Principle:
让主数据库(master)处理事务性增、改、删操作(INSERT、UPDATE、DELETE),而从数据库(slave)处理SELECT查询操作。
2. Advantages:
备份数据库,分担数据库压力,承受更大的访问量。
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
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.
2.3. View the query results
Query the data with the primary key id 1
The following are the query results
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.