[client] port = 3306 socket = /tmp/mysql.sock [mysqld] basedir = /usr/local/mysql port = 3306 socket = /tmp/mysql.sock datadir = /usr/local/mysql/data pid-file = /usr/local/mysql/data/mysql.pid log-error = /usr/local/mysql/data/mysql.err server-id = 2 auto_increment_offset = 2 auto_increment_increment = 2 #偶数ID log-bin = mysql-bin #打开二进制功能,MASTER主服务器必须打开此项 binlog-format=ROW binlog-row-image=minimal log-slave-updates=true gtid-mode=on enforce-gtid-consistency=true master-info-repository=TABLE relay-log-info-repository=TABLE sync-master-info=1 slave-parallel-workers=0 sync_binlog=0 binlog-checksum=CRC32 master-verify-checksum=1 slave-sql-verify-checksum=1 binlog-rows-query-log_events=1 #expire_logs_days=5 max_binlog_size=1024M #binlog单文件最大值 replicate-ignore-db = mysql #忽略不同步主从的数据库 replicate-ignore-db = information_schema replicate-ignore-db = performance_schema replicate-ignore-db = test replicate-ignore-db = zabbix max_connections = 3000 max_connect_errors = 30 skip-character-set-client-handshake #忽略应用程序想要设置的其他字符集 init-connect='SET NAMES utf8' #连接时执行的SQL character-set-server=utf8 #服务端默认字符集 wait_timeout=1800 #请求的最大连接时间 interactive_timeout=1800 #和上一参数同时修改才会生效 sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES #sql模式 max_allowed_packet = 10M bulk_insert_buffer_size = 8M query_cache_type = 1 query_cache_size = 128M query_cache_limit = 4M key_buffer_size = 256M read_buffer_size = 16K skip-name-resolve slow_query_log=1 long_query_time = 6 slow_query_log_file=slow-query.log innodb_flush_log_at_trx_commit = 2 innodb_log_buffer_size = 16M [mysql] no-auto-rehash [myisamchk] key_buffer_size = 20M sort_buffer_size = 20M read_buffer = 2M write_buffer = 2M [mysqlhotcopy] interactive-timeout [mysqldump] quick max_allowed_packet = 16M [mysqld_safe]
1.10 初始化MySQLcd /usr/local/mysql scripts/mysql_install_db --user=mysql
1.11 为启动脚本赋予可执行权限并启动MySQLchmod +x /etc/rc.d/init.d/mysqld /etc/init.d/mysqld start
2. 配置主从同步 2.1 添加主从同步账户masterA上:
mysql> grant replication slave on *.* to 'repl'@'192.168.10.12' identified by '123456'; mysql> flush privileges;
masterB上:
mysql> grant replication slave on *.* to 'repl'@'192.168.10.11' identified by '123456'; mysql> flush privileges;
2.2 查看主库的状态masterA上:
mysql> show master status; +------------------+----------+--------------+------------------+-------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | +------------------+----------+--------------+------------------+-------------------+ | mysql-bin.000003 | 120 | | | | +------------------+----------+--------------+------------------+-------------------+ 1 row in set (0.00 sec)
masterB上