'class' => 'yii\db\Connection',
// 单个数据库配置
// 'dsn' => 'mysql:host=192.168.138.130;dbname=mj_education', // 'username' => 'root', // 'password' => '123456', // 'charset' => 'utf8', // 'tablePrefix'=>'mj_',
-------------------------------
//多个数据库配置实现多主多从
// 配置主服务器
'masterConfig' => [
'username' => 'root',
'password' => '123456',
'charset'=>'utf8',
'tablePrefix'=>'mj_',
'attributes' => [
// use a smaller connection timeout
PDO::ATTR_TIMEOUT => 10,
],
],
// 配置主服务器组
'masters' => [
['dsn' => 'mysql:host=192.168.138.130;dbname=mj_education'],
// ['dsn' => 'dsn for master server 2'],
],
// 配置从服务器
'slaveConfig' => [
'username' => 'test',
'password' => '123456',
'tablePrefix'=>'mj_',
'attributes' => [
// use a smaller connection timeout
PDO::ATTR_TIMEOUT => 10,
],
], // 配置从服务器组
'slaves' =>
[
['dsn' => '192.168.138.131;dbname=mj_education'],
['dsn' => '192.168.138.132;dbname=mj_education'],
// ['dsn' => 'dsn for slave server 3'],
// ['dsn' => 'dsn for slave server 4'],
],
// Schema cache options (for production environment)
//'enableSchemaCache' => true,
//'schemaCacheDuration' => 60,
//'schemaCache' => 'cache',