mysql主從複製搭建

HelloWorld-Q發表於2020-11-30

(1)建立一個用於主從複製的使用者

create user `slave`@`%` identified by "root";
grant all privileges on  *.* to 'slave'@'%'; --給使用者許可權

(2)是否開啟bin-log

 vi /etc/my.cnf
 [mysqld]
 log-bin=mysql-bin
 server-id=1

(3)檢視當前bin-log

 show master status;
mysql> show master status;
+------------------+----------+--------------+------------------+-------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000002 |    10820 |              |                  |                   |
+------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)

(4)從庫配置主從資訊

停止從庫   stop  slave ;

配置從庫 (不要換行,不要換行,不要換行)

change master to master_host='192.168.8.110',master_port=3306,master_user='slave',master_password='root',master_log_file='mysql-bin.000002',master_log_pos=16311;
啟動從庫  start slave;

(5)檢視從庫狀態

  show  slave status \G;

(5)看到2個Yes 主從搭建成功

Slave_IO_Running: Yes
Slave_SQL_Running: Yes

可能存在的問題
從庫的service_id 和主庫一樣了

vi /etc/my.cnf

修改在從新啟動mysql

service mysql restart;

開始主從2庫最好一致,避免其他不同步(採用熱備份)
開始主從2庫最好一致,避免其他不同步(採用熱備份)
開始主從2庫最好一致,避免其他不同步(採用熱備份)

mysql主從複製搭建

本作品採用《CC 協議》,轉載必須註明作者和本文連結
有夢想的人睡不著,沒有夢想的人睡不醒。

相關文章