Home >Database >Mysql Tutorial >Thinkphp框架支持MySQL的读写分离_MySQL

Thinkphp框架支持MySQL的读写分离_MySQL

WBOY
WBOYOriginal
2016-05-31 08:50:241002browse

ThinkPHP

bitsCN.com

以前在做项目时,尝试过用Mysql Proxy和Ameba来解决MySQL的读写分离,但效果都不甚理想,现在手上很多网站和项目都迁到Thinkphp框架了,感觉它的MySQL读写分离功能还是支持得很好的,主要代码如下:

'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_',

注意事项:

1、当采用原生态的sql语句进行写入操作的时候,要用execute,读操作要用query。

2、MySQL数据主从同步还是要靠MySQL的机制来实现,所以这个时候MySQL主从同步的延迟问题是需要优化,延迟时间太长不仅影响业务,还影响用户体验。

 

bitsCN.com
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn