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

歡迎訪問 生活随笔!

生活随笔

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

数据库

MySQL主从复制,读写分离配置

發布時間:2024/4/14 数据库 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 MySQL主从复制,读写分离配置 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

MySQL主從配置


?????? 配置準備將要配置的數據庫進行主從同步,主從的服務器上都要有同一個數據庫

一、配置mysql主服務器

[root@master?~]#?vim?/etc/my.cnf .................................... log-bin=mysql-bin?????<==?打開日志格式 .................................... server-id=1???????????<==?主從標記 ............................... 可選添加配置,篩選庫 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從服務器

#?修改從mysql的配置文件 [root@slave?~]#?vim?/etc/my.cnf ............................... server-id=2?????修改id號,用來區分主從服務器標識 ............................... [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#?這部分沒有錯誤提示,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

???????? 接下來就可以測試主從服務器了





轉載于:https://blog.51cto.com/maocong/1656898

總結

以上是生活随笔為你收集整理的MySQL主从复制,读写分离配置的全部內容,希望文章能夠幫你解決所遇到的問題。

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