mysql 互為主從
ubuntu 服務器mysql5.9
開啟功能分別在主從服務器上編輯mysql配置文件
#vim /etc/mysql/mysql.conf.d/mysqld.cnf 增加下面兩行
bind-address = 0.0.0.0 #修改為允許任意服務器訪問
log-bin=mysql
server-id=1 #主從數字不一樣
重啟服務
#/etc/init.d/mysql restart
進入mysql
建用戶給權限
mysql>grant all privileges on *.* to user@’%’identified by ‘123‘;
mysql>show master status;
1、先在主的上鎖,註意上鎖後在看一下master狀態,保證File和Position不變。
mysql>FLUSH TABLES WITH READ LOCK;
mysql>unlock tables; #解鎖在同步完成之後
2、在從上添加master
mysql>change master to master_host=‘192.168.1.141‘,master_user=‘user‘,
master_password=‘123‘,
master_port=3306,
master_log_file=‘mysql.000002‘,
master_log_pos=154;
查看slave的狀態
mysql>stopslave;
Slave_IO_Runing:Yes
Slave_SQL_Ringing:Yes
正常
如果出現No,看數據庫日誌報錯
Slave SQL for channel ‘‘: Error executing row event: ‘Table ‘yunceshi.ph_smart_contract‘ doesn‘t exist‘, Error_code: 1146
配置文件中增加 slave-skip-errors = 1146
還可以把住的數據庫備份,在導入到從的數據庫中。
mysql 互為主從