本文主要介紹了兩個MySQL版本的準備工作,強調了設置權限登陸服務器,使用root登陸MySQL,并設置了權限grant all privileges on database名.* to '用戶名'@'%' identified by...
準備工作
兩個不同的MySQL。
建議MySQL版本不要太大,否則會出現各種問題,如果你的主從版本差異較大,請自行百度設置同步后可能出現的問題。
設置權限
登陸服務器,進入MySQL,推薦使用root登陸MySQL;
mysql -u root -p
設置權限
grant all privileges on 數據庫名.* to '用戶名'@'%' identified by '密碼';
flush privileges;
注意:兩個數據庫都要設置
啟用主從同步
獲取master_log_file和master_log_pos值
在主庫執行如下語句:
flush logs;//用于刷新,可以不執行這句
show master status;
得到如下的內容:
點擊添加圖片描述(最多60個字)編輯
其中File就是master_log_file,Postion就是master_log_pos。
本次截圖,master_log_file=‘mysql-bin.000013’, master_log_pos=1276
執行同步
在備庫執行如下語句:
STOP SLAVE;
reset slave;
change master to master_host='主庫ip',master_port=端口號,master_user='用戶名',master_password='密碼',master_log_file='前面獲取的
master_log_file',master_log_pos=前面獲取的master_log_pos;
start slave;
查看同步狀態
show slave status;
show slave status\G;
錯誤一解決
Fatal error: The slave I/O thread stops because master and slave have equal MySQL server ids; these ids must be different for replication to work (or the --replicate-same-server-id option must be used on slave but this does not always make sense; please check the manual before using it).
出現上述問題的原因是主從的server ids一致,需要不一樣。進入主數據庫或者從數據庫服務器,打開/etc/my.conf文件,修改server-id為其它的值;
原文來源:https://mp.weixin.qq.com/s/ai5E8OZlHQKXtdwh_27yFg
來源:本文內容搜集或轉自各大網絡平臺,并已注明來源、出處,如果轉載侵犯您的版權或非授權發布,請聯系小編,我們會及時審核處理。
聲明:江蘇教育黃頁對文中觀點保持中立,對所包含內容的準確性、可靠性或者完整性不提供任何明示或暗示的保證,不對文章觀點負責,僅作分享之用,文章版權及插圖屬于原作者。
Copyright?2013-2024 JSedu114 All Rights Reserved. 江蘇教育信息綜合發布查詢平臺保留所有權利
蘇公網安備32010402000125
蘇ICP備14051488號-3技術支持:南京博盛藍睿網絡科技有限公司
南京思必達教育科技有限公司版權所有 百度統計