Compared with other methods to achieve MySQL read-write separation, using the Thinkphp framework to achieve MySQL read-write separation is simple and easy to use. The sample code of its configuration file is as follows:
'DB_TYPE'=> 'mysql', 'DB_DEPLOY_TYPE' => 1, //开打支持多服务器 'DB_RW_SEPARATE'=>true,//数据库读写否分离 'DB_HOST'=> '192.168.11.101,192.168.11.102', 'DB_NAME'=>'test', 'DB_USER'=>'admin', 'DB_PWD'=>'admin101', 'DB_PREFIX' => 'fav_',
Note:
1. When using the original sql statement for writing operations, execute is used, and query is used for reading operations.
2. MySQL data master-slave synchronization still relies on the MySQL mechanism, so at this time the delay problem of MySQL master-slave synchronization needs to be optimized . Too long delay time not only affects the business, but also affects the user experience.