windows mysql主 Linux mysql 从 主从同步,读写分离

Mysql 读写分离

YIi 配置

 

<?php

return [
    ‘class‘ => ‘yii\db\Connection‘,
    ‘masterConfig‘ => [
               // ‘dsn‘ => ‘mysql:host=localhost;dbname=studyyii‘,
                ‘username‘ => ‘root‘,
                ‘password‘ => ‘caesar‘,
                ‘charset‘ => ‘utf8‘,
                ‘attributes‘ => [
                    // use a smaller connection timeout
                    PDO::ATTR_TIMEOUT => 10,
                ],
    ],

    // 配置主服务器组
    ‘masters‘ => [
        [‘dsn‘ => ‘mysql:host=172.31.80.31;dbname=studyyii‘],
      //  [‘dsn‘ => ‘dsn for master server 2‘],
    ],

    // 配置从服务器
    ‘slaveConfig‘ => [
        ‘username‘ => ‘root‘,
        ‘password‘ => ‘root‘,
        ‘charset‘ => ‘utf8‘,
        ‘attributes‘ => [
            // use a smaller connection timeout
            PDO::ATTR_TIMEOUT => 10,
        ],
    ],
    // 配置从服务器组
    ‘slaves‘ => [
        [‘dsn‘ => ‘mysql:host=localhost;dbname=studyyii‘],
    ],
];

 

 

 

 

 

 

Linux mysql master

My.cnf:

server_id = 1   #从服务器标识,范围1---2E32-1

log_bin = mysql_bin

binlog_do_db = studyyii

binlog_do_db = mysql

 

 mysql service restart

 

windows mysql slave

 

mysql.ini:

[mysqld]

port=3306

server-id = 2

replicate-do-db = study

 

重启mysql

登陆mysql

mysql> stop slave;

mysql> change master to master_host=‘192.168.1.200‘,master_user=‘root‘,master_password=‘123456‘;

mysql> start slave;

mysql> show slave status\G;

 

查看这两项是否为YES,yes为正常。

Slave_IO_Running: Yes

Slave_SQL_Running: Yes

 

Ok 了 读写分离,主从同步

 

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。