安静
PHP技术博客

131101 discuz x3 主从数据库配置

discuz x3 配置安装文件 官方描述因为是藏在安装包里的 并没有对外公布:

// ----------------------------  CONFIG DB  ----------------------------- //
// ----------------------------  数据库相关设置---------------------------- //
/**
* 数据库主服务器设置, 支持多组服务器设置, 当设置多组服务器时, 则会根据分布式策略使用某个服务器
* @example
* $_config['db']['1']['dbhost'] = 'localhost'; // 服务器地址
* $_config['db']['1']['dbuser'] = 'root'; // 用户
* $_config['db']['1']['dbpw'] = 'root';// 密码
* $_config['db']['1']['dbcharset'] = 'gbk';// 字符集
* $_config['db']['1']['pconnect'] = '0';// 是否持续连接
* $_config['db']['1']['dbname'] = 'x1';// 数据库
* $_config['db']['1']['tablepre'] = 'pre_';// 表名前缀
*
* $_config['db']['2']['dbhost'] = 'localhost';
* ...
*
*/
$_config['db'][1]['dbhost']             = 'localhost';
$_config['db'][1]['dbuser']             = 'root';
$_config['db'][1]['dbpw']               = 'root';
$_config['db'][1]['dbcharset']          = 'utf8';
$_config['db'][1]['pconnect']           = 0;
$_config['db'][1]['dbname']             = 'ultrax';
$_config['db'][1]['tablepre']           = 'pre_';
/**
* 数据库从服务器设置( slave, 只读 ), 支持多组服务器设置, 当设置多组服务器时, 系统根据每次随机使用
* @example
* $_config['db']['1']['slave']['1']['dbhost'] = 'localhost';
* $_config['db']['1']['slave']['1']['dbuser'] = 'root';
* $_config['db']['1']['slave']['1']['dbpw'] = 'root';
* $_config['db']['1']['slave']['1']['dbcharset'] = 'gbk';
* $_config['db']['1']['slave']['1']['pconnect'] = '0';
* $_config['db']['1']['slave']['1']['dbname'] = 'x1';
* $_config['db']['1']['slave']['1']['tablepre'] = 'pre_';
* $_config['db']['1']['slave']['1']['weight'] = '0'; //权重:数据越大权重越高
*
* $_config['db']['1']['slave']['2']['dbhost'] = 'localhost';
* ...
*
*/
$_config['db']['1']['slave'] = array();
//启用从服务器的开关
$_config['db']['slave'] = false;
/**
* 数据库 分布部署策略设置
*
* @example 将 common_member 部署到第二服务器, common_session 部署在第三服务器, 则设置为
* $_config['db']['map']['common_member'] = 2;
* $_config['db']['map']['common_session'] = 3;
*
* 对于没有明确声明服务器的表, 则一律默认部署在第一服务器上
*
*/
$_config['db']['map'] = array();
/**
* 数据库 公共设置, 此类设置通常对针对每个部署的服务器
*/
$_config['db']['common'] = array();
/**
*  禁用从数据库的数据表, 表名字之间使用逗号分割
*
* @example common_session, common_member 这两个表仅从主服务器读写, 不使用从服务器
* $_config['db']['common']['slave_except_table'] = 'common_session, common_member';
*
*/
$_config['db']['common']['slave_except_table'] = '';

 

 

实际demo:

$_config['db']['slave'] = true;
$_config['db']['1']['slave'] = array();
$_config['db']['1']['slave']['1']['dbhost'] = 'localhost';
$_config['db']['1']['slave']['1']['dbuser'] = 'slave';
$_config['db']['1']['slave']['1']['dbpw'] = 'slave';
$_config['db']['1']['slave']['1']['dbcharset'] = 'utf8';
$_config['db']['1']['slave']['1']['pconnect'] = '0';
$_config['db']['1']['slave']['1']['dbname'] = 'ultrax';
$_config['db']['1']['slave']['1']['tablepre'] = 'pre_';
$_config['db']['1']['slave']['1']['weight'] = '99';
//再使用过程中可能会有BUG 会在未来的时间里去更新 解决为什么会产生这个BUG 可能是不规范的 开发导致
//暂时性的BUG解决
// source/class/db/db_driver_mysql_slave.php 参数设置为1
public $serverid = 1;
赞(0) 打赏
未经允许不得转载:AJ's Blog » 131101 discuz x3 主从数据库配置
分享到: 更多 (0)

评论 1

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
  1. #-49

    感谢楼主分享

    外教7年前 (2013-11-14)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏