MySQL主从复制,读写分离配置
生活随笔
收集整理的這篇文章主要介紹了
MySQL主从复制,读写分离配置
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
MySQL主從配置
?????? 配置準(zhǔn)備將要配置的數(shù)據(jù)庫進(jìn)行主從同步,主從的服務(wù)器上都要有同一個(gè)數(shù)據(jù)庫
一、配置mysql主服務(wù)器
[root@master?~]#?vim?/etc/my.cnf .................................... log-bin=mysql-bin?????<==?打開日志格式 .................................... server-id=1???????????<==?主從標(biāo)記 ............................... 可選添加配置,篩選庫 binlog-do-db=db1,db2?#需要同步的庫 binlog-ignore-db=db1,db2?#忽略不同步的庫 ............................. [root@master?backup]#?mysql?-uroot?-p Enter?password: Welcome?to?the?MySQL?monitor.??Commands?end?with?;?or?\g. Your?MySQL?connection?id?is?1 Server?version:?5.5.42-log?MySQL?Community?Server?(GPL)Copyright?(c)?2000,?2015,?Oracle?and/or?its?affiliates.?All?rights?reserved.Oracle?is?a?registered?trademark?of?Oracle?Corporation?and/or?its affiliates.?Other?names?may?be?trademarks?of?their?respective owners.Type?'help;'?or?'\h'?for?help.?Type?'\c'?to?clear?the?current?input?statement.mysql>?grant?replication?slave?on?*.*?to?'repl'@'192.168.1.13'?identified?by?'123'; Query?OK,?0?rows?affected?(0.00?sec)mysql>mysql>?flush?privileges; Query?OK,?0?rows?affected?(0.00?sec)mysql>?flush?tables?with?read?lock; Query?OK,?0?rows?affected?(0.00?sec)mysql>?show?master?status; +------------------+----------+--------------+------------------+ |?File?????????????|?Position?|?Binlog_Do_DB?|?Binlog_Ignore_DB?| +------------------+----------+--------------+------------------+ |?mysql-bin.000014?|??????332?|??????????????|??????????????????| +------------------+----------+--------------+------------------+二、配置mysql從服務(wù)器
#?修改從mysql的配置文件 [root@slave?~]#?vim?/etc/my.cnf ............................... server-id=2?????修改id號,用來區(qū)分主從服務(wù)器標(biāo)識 ............................... [root@slave?tmp]#?mysql?-uroot?-p Enter?password: Welcome?to?the?MySQL?monitor.??Commands?end?with?;?or?\g. Your?MySQL?connection?id?is?8 Server?version:?5.5.43-log?MySQL?Community?Server?(GPL)Copyright?(c)?2000,?2015,?Oracle?and/or?its?affiliates.?All?rights?reserved.Oracle?is?a?registered?trademark?of?Oracle?Corporation?and/or?its affiliates.?Other?names?may?be?trademarks?of?their?respective owners.Type?'help;'?or?'\h'?for?help.?Type?'\c'?to?clear?the?current?input?statement.mysql>?slave?stop; Query?OK,?0?rows?affected,?1?warning?(0.00?sec)mysql>?change?master?to?master_host='192.168.1.11',?master_port=3306,?master_user='repl',master_password='123',?master_log_file='mysql-bin.000014',?master_log_pos=332; Query?OK,?0?rows?affected?(0.08?sec)mysql>?slave?start; Query?OK,?0?rows?affected?(0.01?sec)mysql>?show?slave?status\G; ***************************?1.?row?***************************Slave_IO_State:?Waiting?for?master?to?send?eventMaster_Host:?192.168.1.11Master_User:?replMaster_Port:?3306Connect_Retry:?60Master_Log_File:?mysql-bin.000014Read_Master_Log_Pos:?332Relay_Log_File:?slave-relay-bin.000003Relay_Log_Pos:?253Relay_Master_Log_File:?mysql-bin.000014#?這部分提示為,YESSlave_IO_Running:?YesSlave_SQL_Running:?YesReplicate_Do_DB:Replicate_Ignore_DB:Replicate_Do_Table:Replicate_Ignore_Table:Replicate_Wild_Do_Table:Replicate_Wild_Ignore_Table:Last_Errno:?0Last_Error:Skip_Counter:?0Exec_Master_Log_Pos:?332Relay_Log_Space:?409Until_Condition:?NoneUntil_Log_File:Until_Log_Pos:?0Master_SSL_Allowed:?NoMaster_SSL_CA_File:Master_SSL_CA_Path:Master_SSL_Cert:Master_SSL_Cipher:Master_SSL_Key:Seconds_Behind_Master:?0 Master_SSL_Verify_Server_Cert:?No#?這部分沒有錯(cuò)誤提示,OKLast_IO_Errno:?0Last_IO_Error:Last_SQL_Errno:?0Last_SQL_Error:Replicate_Ignore_Server_Ids:Master_Server_Id:?1 1?row?in?set?(0.00?sec)ERROR: No?query?specified???????? 接下來就可以測試主從服務(wù)器了
轉(zhuǎn)載于:https://blog.51cto.com/maocong/1656898
總結(jié)
以上是生活随笔為你收集整理的MySQL主从复制,读写分离配置的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: RHCS图形界面建立GFS共享下
- 下一篇: C++实践参考——OOP版电子词典