MYSQL配置主從同步

來源:互聯網
上載者:User

標籤:socket   commit   com   bst   解鎖   預設   table   /etc   serve   

MYSQL配置主從同步mysql主伺服器配置
vim /etc/my.cnf[mysqld]datadir=/var/lib/mysqlsocket=/var/lib/mysql/mysql.socksymbolic-links=0lower_case_table_names=1sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES #設定資料庫標識server-id=2#任何一個事務提交之後就立即寫入到磁碟中的二進位檔案sync_binlog=1#保持資料一致性,建議配置innodb_flush_log_at_trx_commit=1#開啟伺服器二進位日誌log-bin=mysql-bin# 為每個session 分配的記憶體,在事務過程中用來儲存二進位日誌的緩衝binlog_cache_size=1M  # 主從複製的格式(mixed,statement,row,預設格式是statement)binlog_format=mixed  # 二進位日誌自動刪除/到期的天數。預設值為0,表示不自動刪除。expire_logs_days=7  # 如果只有一個資料庫,可配置,否則不要建議配置,bin-log Position值不變化,影響同步#binlog-do-db=db1,db2binlog-ignore-db=mysql[mysqld_safe]log-error=/var/log/mysqld.logpid-file=/var/run/mysqld/mysqld.pid
mysql從伺服器配置
vim /etc/my.cnf[mysqld]datadir=/var/lib/mysqlsocket=/var/lib/mysql/mysql.socksymbolic-links=0lower_case_table_names=1sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES #設定資料庫標識server-id=1replicate-do-db=db1replicate-ignore-db=mysql[mysqld_safe]log-error=/var/log/mysqld.logpid-file=/var/run/mysqld/mysqld.pid
配置主從

Master DB Server IP:192.168.1.216
Slave DB Server IP:192.168.1.217

# 主伺服器建立帳號,確保Slave伺服器能訪問Master伺服器資料庫Mysql > grant replication slave on *.* to [email protected] identified by '[email protected]';Mysql > flush privileges;Mysql > show variables like 'server_id';Mysql > show variables like '%bin';# 主要資料庫鎖表唯讀Mysql > flush tables with read lock;Mysql > show master status;# 從庫匯入資料庫Mysql > change master to MASTER_HOST='192.168.1.216',MASTER_PORT=3306,MASTER_USER='backup',MASTER_PASSWORD='[email protected]',MASTER_LOG_FILE='mysql-bin.00001',MASTER_LOG_POS=1000,master_connect_retry=30;# 查看狀態,啟動從庫線程Mysql > show slave status\GMysql > start slave;# 查看同步狀態Mysql > show slave status\G# 出現Slave_IO_Running: YesSlave_SQL_Running: Yes# 即配置成功# 主庫解鎖資料庫Mysql > unlock tables;

MYSQL配置主從同步

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.