1. 程式人生 > >linux上 mysql主從配置

linux上 mysql主從配置

準備工作:主從上都先關閉iptables和firewalld以及selinux
注意事項:所有主從的id號不能重複!!

1:mysql主,啟動日誌,和設定id號
   在[mysqld]下新增
   
   log-bin=mysql-bin
   binlog_format=mixed
   server-id   = 1

2:mysql從,設定id號(所有主從的id號不能重複!!)
   server-id   = 2   ##mysql從 多的話,以次類推1 2 3 4 5 6

3:重啟主從mysql服務

4:主mysql授權使用者

   建立主從同步的使用者
   mysql -uroot -p"$mysqlpass" -e  "grant replication slave on *.* to 'zzh'@'資料庫密碼' identified by 'Zzh911218~';"
   mysql -uroot -p"$mysqlpass" -e  "grant all privileges on *.* to [email protected]'資料庫密碼' with grant option;"
   mysql -uroot -p"$mysqlpass" -e  "flush privileges;"

5:在主庫上檢視日誌名稱和偏移量
   show master status;

6:從庫上指定主庫資訊
   change master to master_host='主庫ip',master_user='zzh',master_password='Zzh911218~',master_log_file='日誌名稱',master_log_pos=偏移量 ;

   再啟動slave:  start slave;
   再檢視從狀態: show slave status\G;(兩個yes即可)