主數據庫執行命令:mysql
show master status;sql
獲得結果
mysql-bin.000009
2123數據庫
從數據庫執行命令windows
stop slave;測試
change master to
master_host='47.95.247.135',
master_port=3306,
master_user='root',
master_password='root',
master_log_file='mysql-bin.000009',
master_log_pos=4353;lua
start slave;debug
show slave status;orm
--回滾server
set GLOBAL SQL_SLAVE_SKIP_COUNTER=1;中間件
從數據庫更改,或者主數據庫刪除更改了從數據庫沒有的記錄,則會引發Slave_SQL_Running 爲:NO
重複執行以上操做,設置master_log_file和master_log_pos
主數據庫my.ini
server-id=1
log-bin=mysql-bin
#從庫會基於此log-bin來作複製,多個就在下面再寫一個
binlog-do-db=hsf
binlog-do-db=smarthome
#用於讀寫分離的具體數據庫,這裏我建立了mytest做測試
binlog_ignore_db=mysql
#不用於讀寫分離的具體數據庫
binlog_ignore_db=information_schema
#和binlog-do-db同樣,能夠設置多個
從數據庫my.ini
server-id=2
log-bin=mysql-bin
#從庫會基於此log-bin來作複製
replicate-do-db=hsf
replicate-do-db=smarthome
#用於讀寫分離的具體數據庫,這裏我建立了mytest做測試
中間件
mysql-proxy.conf
[mysql-proxy]
admin-username=root
admin-password=root
admin-lua-script=C:/soft/mysql-proxy-0.8.5-windows-x86-32bit/lib/mysql-proxy/lua/admin.lua
proxy-backend-addresses=47.95.247.135:3306
proxy-read-only-backend-addresses=47.93.253.194:3306
proxy-lua-script=C:/soft/mysql-proxy-0.8.5-windows-x86-32bit/share/doc/mysql-proxy/rw-splitting.lua
log-file=C:/soft/mysql-proxy-0.8.5-windows-x86-32bit/log/mysql-proxy.log
log-level=debug
daemon=true
keepalive=true
bat啓動文件install.bat
mysql-proxy -P 172.17.118.190:6217 --defaults-file=C:\soft\mysql-proxy-0.8.5-windows-x86-32bit\bin\mysql-proxy.conf