首先主从我是在同一台mysql服务器上进行的 从配置文件中可以看到,在common/config/main_loacal.php [ 'db' => [ 'class' => 'yii\db\Connection', 'dsn' => 'mysql:host=localhost;dbname=yjz_data', 'username' => 'root', 'password' => 'root', 'charset' => 'utf8', // 配置从服务器 'slaveConfig' => [ 'username' => 'root', 'password' => 'root', 'attributes' => [ // use a smaller connection timeout PDO::ATTR_TIMEOUT => 10, ], ], // 配置从服务器组 'slaves' => [ ['dsn' => 'mysql:host=localhost;dbname=yjz_data1'], ['dsn' => 'mysql:host=localhost;dbname=yjz_data2'], ], ], 'mailer' => [ 'class' => 'yii\swiftmailer\Mailer', 'viewPath' => '@common/mail', // send all mails to a file by default. You have to set // 'useFileTransport' to false and configure a transport // for the mailer to send real emails. 'useFileTransport' => true, ], ], ]; 配置中有注释的部分,// 配置从服务器 和 // 配置从服务器组 这样就可以实现主从了
查看原文:http://www.architecy.com/archives/364
yii2 advance版简易主从搭建测试
最新推荐文章于 2022-06-16 14:50:26 发布
首先主从我是在同一台mysql服务器上进行的
从配置文件中可以看到,在common/config/main_loacal.php
[
'db' => [
'class' => 'yii\db\Connection',
'dsn' => 'mysql:host=localhost;dbname=yjz_data',
'username' => 'root',
'password' => 'root',
'charset' => 'utf8',
// 配置从服务器
'slaveConfig' => [
'username' => 'root',
'password' => 'root',
'attributes' => [
// use a smaller connection timeout
PDO::ATTR_TIMEOUT => 10,
],
],
// 配置从服务器组
'slaves' => [
['dsn' => 'mysql:host=localhost;dbname=yjz_data1'],
['dsn' => 'mysql:host=localhost;dbname=yjz_data2'],
],
],
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
'viewPath' => '@common/mail',
// send all mails to a file by default. You have to set
// 'useFileTransport' to false and configure a transport
// for the mailer to send real emails.
'useFileTransport' => true,
],
],
];
配置中有注释的部分,// 配置从服务器 和 // 配置从服务器组
这样就可以实现主从了
860

被折叠的 条评论
为什么被折叠?



