mysql下载:https://downloads.mysql.com/archives/community/
1、配置my.cnf,根据主从库环境打开或关闭部分选项
datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock symbolic-links=0 #event_scheduler=1 log-error=/var/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid server_id=11 log_bin=mysql-bin binlog_format=row log_slave_updates=1 expire_logs_days=10 log_slave_updates=1 relay_log=/var/log/relay.log slow_query_log=on long_query_time=1 slow_query_log_file=/var/log/slow-query.log skip_name_resolve=1 max_connections=1000 open_files_limit=65535 table_open_cache=5120 innodb_file_per_table=1 innodb_flush_log_at_trx_commit=2 sync_binlog=1 max_connect_errors=200 default_password_lifetime=0 join_buffer_size = 1M sort_buffer_size = 2M max_allowed_packet = 32M innodb_open_files = 3000 innodb_buffer_pool_size=4G innodb_log_buffer_size=16M # read-only=1
2、主库授权用户
GRANT REPLICATION SLAVE,REPLICATION CLIENT ON *.* TO 'repl'@'%' IDENTIFIED BY 'xxxxxx';
3、主库全备
mysqldump -uroot -p --single-transaction -R --default-character-set=utf8 --triggers --events --hex-blob --flush-logs --master-data=2 -A >all.sql
4、备库操作,导入数据
show processlist; show databases; source /tmp/all.sql
cat all.sql
-- CHANGE MASTER TO MASTER_LOG_FILE='mysql-bin.000001', MASTER_LOG_POS=154;
5、change maser 到主库
change master to master_host='xxxxx', master_user='repl', master_password='xxxx', master_port=3306, master_log_file='mysql-bin.000002', master_log_pos=154; start slave; show slave status;
从库的额外参数:
1、slave_exec_mode
2、max_allowd_packet
3、slave_compressed_protocal
4、read-only
5、slave_net_timeout
6、--slave-skip-errors=1062,1053
7、skip-slave-start