MYSQL主主同步配置文件
在實際業務應用中,MYSQL主主同步可以為業務數據備份、主從切換等提供開箱即用的支持。本文將介紹MYSQL主主同步配置文件的相關內容。
MYSQL主主同步配置文件的建議參考:
#MYSQL General Configuration File [client] port=3306 socket=/tmp/mysql.sock default-character-set=utf8mb4 [mysqld] port=3306 datadir=/var/lib/mysql socket=/tmp/mysql.sock user=mysql # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 default-storage-engine=InnoDB max_allowed_packet=512M open_files_limit=65535 character-set-server=utf8mb4 collation-server=utf8mb4_unicode_ci #Replicarion server-id=1 relay-log=/var/lib/mysql/mysql-relay.log relay-log-index=/var/lib/mysql/mysql-relay.index log_slave_updates=1 auto_increment_increment=2 auto_increment_offset=1 binlog-format=ROW binlog-ignore-db=mysql #Logging log-error=/var/log/mysqld.log log_bin=/var/lib/mysql/mysql-bin.log expire_logs_days=7 max_binlog_size=100M #MYSQL Master Slave Replication read_only=0 binlog-ignore-db=information_schema log_bin=mysql-bin binlog_format=ROW binlog-ignore-db=cache sync_binlog=1 server-id=1 innodb_flush_log_at_trx_commit=2 #Slave relay-log=mysql-relay-bin relay-log-index=mysql-relay-bin.index replicate-do-db=music replicate-rewrite-db=blog->blog_copy replicate-wild-do-table=employees.% replicate-ignore-db=mysql slave-parallel-workers=4 slave-parallel-type=LOGICAL_CLOCK slave-skip-errors=1062,1146
在MYSQL主主同步配置文件中,需要注意的重點配置項如下:
- server-id
- log_bin、binlog_format
- replicate-do-db、replicate-rewrite-db、replicate-wild-do-table、binlog-ignore-db
MYSQL主主同步需要在兩臺不同的MYSQL服務器上分別設置server-id,以區分主從屬關系。
MYSQL主主同步需要啟用二進制日志BIN LOG,才能實現數據同步。需要在MYSQL配置文件中指定BIN LOG存儲路徑(log_bin)和格式(binlog_format),同時設置log_slave_updates為1。
針對不同的數據庫和數據表,可以使用這幾個選項進行同步配置。通過replicate-do-db和replicate-rewrite-db,可以控制數據同步的目標數據庫和表名;replicate-wild-do-table可以實現通配符匹配,支持多個數據表的同步;binlog-ignore-db則用于忽略一些不需要同步的數據庫。
上一篇mysql四舍五入函數
下一篇精簡代碼div css