參考網址:https://www.juduo.cc/club/3579790.html
https://tknl45.pixnet.net/blog/post/241768457
主從搭建 – 部署流程(Master Slave Replication )
https://ithelp.ithome.com.tw/articles/10267651
https://tw511.com/a/01/15779.html
slave一直法順利登入master
原因是mysql的安全機制
用telnet 192.168.1.9 3306 會發現被拒絕,無法連入
端口3306在我的Ubuntu服務器上似乎已關閉
問題在於服務器僅在內部進行偵聽。
從/etc/mysql/my.cnf
刪除行bind-address 127.0.0.1
解決了該問題。
較新版本的Ubuntu(≥16.04)在/etc/mysql/mysql.conf.d/mysqld.cnf
中可能有此行。
一些錯誤情況的處理方法
https://xdeath.tw/read.php?14
網管人
https://www.netadmin.com.tw/netadmin/zh-tw/technology/12B7B6D6D2F7428085C43CA313D02E93?page=3
https://ssorc.tw/211/%E8%B3%87%E6%96%99%E5%BA%AB%E5%90%8C%E6%AD%A5-mysql-%2B-replication/
註2
slave上會有兩個檔master.info與relay-log.info
如果slave 當機或stop時,重新啟動後,會去讀取這兩檔,繼續從上次中斷點開始未完成的備份
註3
如果資料還是沒有同步的話,可能是slave沒有設定成功,可刪掉相關設定檔,重新設定。
cd /var/lib/mysql
rm -f *-bin.*
rm -f master.info
註4
其它指令
mysql> show processlistG
mysql> show master logsG
mysql> purge master logs to 'xxxxx-bin.004' # 刪除xxxxx-bin.004之前的log檔資料
測試過程中用到的指令 GRANT FILE ON *.* TO 'backup'@'120.116.xx.xx' IDENTIFIED BY 'passwd'; GRANT REPLICATION SLAVE ON *.* TO 'backup'@"120.116.xx.xx" IDENTIFIED BY 'passwd'; https://tyeydy.com/mysql-command-create-user/ CREATE USER 'backup'@'120.116.xx.xx' IDENTIFIED BY 'passwd'; GRANT FILE ON *.* TO 'backup'@'120.116.xx.xx'; GRANT REPLICATION SLAVE ON *.* TO 'backup'@'120.116.xx.xx'; FLUSH PRIVILEGES; show variables like 'server_id'; show master status; 主從搭建 - 部署流程(Master Slave Replication ) [mysqld] server-id=2 master-host=sa.xxx.xxx master-host=125.228.xx.xx master-user=backup master-password=passwd master-port=3306 master-connect-retry=60 replicate-do-db=ns change master to master_user='backup',master_password='passwd',master_host='192.168.1.9',master_log_file='mysql-bin.000003',master_log_pos=157,get_master_public_key=1; change master to master_user='backup',master_password='passwd',master_host='sa.xx.xx',master_log_file='mysql-bin.000003',master_log_pos=157,get_master_public_key=1; Slave_IO_Running: Connecting create user 'backup'@'%' identified by 'passwd'; grant replication slave on *.* to 'backup'@'%'; change master to master_user='backup',master_password='passwd',master_host='192.168.1.9',master_log_file='mysql-bin.000007',master_log_pos=3530,get_master_public_key=1; https://www.est.idv.tw/%E4%BD%BF%E7%94%A8phpmyadmin%E5%BB%BA%E7%AB%8B-mysql-replication-%E4%B8%BB%E5%BE%9E%E5%82%99%E6%8F%B4/ https://blog.csdn.net/weixin_39864101/article/details/113582490 测试时发现之前库不一致时我在主库里面添加一张表,而从库没有那个库,导致从库 slave 会报错,执行这个命令后重启从库就可以跳过这个错误。 #SET GLOBAL SQL_SLAVE_SKIP_COUNTER = 1 跳过一个事务