日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

yii mysql 主从_mysql主从同步实践 YII

發布時間:2023/12/2 数据库 20 豆豆
生活随笔 收集整理的這篇文章主要介紹了 yii mysql 主从_mysql主从同步实践 YII 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

1、兩臺服務器互聯master、slave 2、master配置: server-id = 1 master端ID號 log-bin=/data/logbin/mysql-bin 日志路徑及文件名 #binlog-do-db = cacti 同步cacti,此處關閉的話,就是除不允許的,其它的庫均同步。 binlog-ignore-db = mysql 不同步mysql

1、兩臺服務器互聯master、slave

2、master配置:

server-id = 1 master端ID號

log-bin=/data/logbin/mysql-bin 日志路徑及文件名

#binlog-do-db = cacti 同步cacti,此處關閉的話,就是除不允許的,其它的庫均同步。

binlog-ignore-db = mysql 不同步mysql庫,以下同上

mysql>show master status;

3、slave配置:

server-id = 2 slave的ID號,此處一定要大于master端。

保存退出。

/usr/local/mysql/bin/mysqladmin -uroot -p shutdown

tar xvzf /data/mysql/cacti.tgz /data/mysql/cacti

chown -R mysql.mysql /data/mysql/cacti

/usr/local/mysql/bin/mysql -uroot -p

mysql>stop slave;

mysql>change master to

>master_host='192.168.2.67',

>master_user='rsync', master端創建的用于主從同步的賬戶和密碼

>master_password='123456',

>master_port='3306', master端設置的client端使用的端口號。

>master_log_file='mysql-bin.000047', master端記錄的file值

>master_log_pos=391592414; master端記錄的position值

mysql>start slave;

mysql>show slave status \G

==========================================================

',

* 'slaves'=>array(

* array('connectionString'=>'mysql://'),

* array('connectionString'=>'mysql://'),

* )

* )

* )

* */

public $slaves=array();

/**

* Whether enable the slave database connection.

* Defaut is true.Set this property to false for the purpose of only use the master database.

* @var bool $enableSlave

* */

public $enableSlave=true;

/**

* @override

* @var bool $autoConnect Whether connect while init

* */

public $autoConnect=false;

/**

* @var CDbConnection

*/

private $_slave;

/**

* Creates a CDbCommand object for excuting sql statement.

* It will detect the sql statement's behavior.

* While the sql is a simple read operation.

* It will use a slave database connection to contruct a CDbCommand object.

* Default it use current connection(master database).

*

* @override

* @param string $sql

* @return CDbCommand

* */

public function createCommand($sql) {

if ($this->enableSlave && !$this->getCurrentTransaction() && self::isReadOperation($sql)) {

return $this->getSlave()->createCommand($sql);

} else {

return parent::createCommand($sql);

}

}

/**

* Construct a slave connection CDbConnection for read operation.

* @return CDbConnection

* */

public function getSlave() {

if (!isset($this->_slave)) {

foreach ($this->slaves as $slaveConfig) {

if (!isset($slaveConfig['class']))

$slaveConfig['class']='CDbConnection';

try {

if ($slave=Yii::createComponent($slaveConfig)) {

Yii::app()->setComponent('dbslave',$slave);

$this->_slave=$slave;

break;

}

} catch (Exception $e) {

echo ''; var_dump($e);echo '';}

}

if (!$this->_slave) {

$this->_slave=clone $this;

$this->_slave->enableSlave=false;

}

}

return $this->_slave;

}

/**

* Detect whether the sql statement is just a simple read operation.

* Read Operation means this sql will not change any thing ang aspect of the database.

* Such as SELECT,DECRIBE,SHOW etc.

* On the other hand:UPDATE,INSERT,DELETE is write operation.

* */

public function isReadOperation($sql) {

return preg_match('/^\s*(SELECT|SHOW|DESC|PRAGMA)\s+/i',$sql);

}

}

==================================================

'db'=>array(

//'connectionString' => 'mysql:host=localhost;dbname=yiitest',

'class' => 'DbConnectionMan',

'connectionString' => 'mysql:host=localhost;dbname=ms_test',

'emulatePrepare' => true,

//'tablePrefix' => 'ms_',

'username' => 'root',

'password' => '123456',

'charset' => 'utf8',

// 'enableProfiling' => true,

// 'enableParamLogging' => true,

'slaves' => array(

array('connectionString' => 'mysql:host=10.237.94.13;dbname=ms_test',

// 'class' => 'CDbConnection',

'username' => 'yanghuolong',

'password' => '123456',

'enableProfiling' => true,

'enableParamLogging' => true,

'charset' => 'utf8'),

),

),

本文原創發布php中文網,轉載請注明出處,感謝您的尊重!

總結

以上是生活随笔為你收集整理的yii mysql 主从_mysql主从同步实践 YII的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。