This article mainly introduces Thinkphp's method for implementing MySQL read/write splitting. For more information about how to implement MySQL read/write splitting, use Thinkphp framework to implement MySQL read/write splitting, the configuration file sample code is as follows:
'Db _ type' => 'mysql', 'DB _ DEPLOY_TYPE '=> 1, // enable multi-server 'DB _ RW_SEPARATE' => true, // whether the database reads/writes are separated by 'DB _ host' => '2017. 168.11.101, 192.168.11.102 ', 'DB _ name' => 'test', 'DB _ user' => 'admin', 'DB _ pwd' => 'admin101 ', 'db _ prefix' => 'fav _',
Note:
1. execute and query are used for read operations when the original SQL statement is used for write operations.
2. MySQL data master-slave synchronization depends on the MySQL mechanism. Therefore, the latency of MySQL master-slave synchronization needs to be optimized at this time. a long delay not only affects the business, it also affects user experience.