Mysql 主从同步配置

三、Mysql主从同步的配置

主库IP:192.168.1.2

从库IP:192.168.1.3

添加一个用于主从同步的用户:

GRANT REPLICATION SLAVE ON . TO 'slave_repl'@'%' IDENTIFIED BY 'slave_repl_mysql';

如果监控mysql主从的话,请加上一个super权限:

GRANT SUPER, REPLICATION SLAVE ON . TO 'slave_repl'@'%' IDENTIFIED BY 'slave_repl_mysql';

主库 conf配置

[mysqld]
server-id=108
#log-bin=/home/mysql/logs/binlog/bin-log
#log_bin=ON
#log_bin_basename=/home/mysql/logs/binlog/bin-log
#log_bin_index=/home/mysql/mysql-bin.index
log_bin=/home/mysql/mysql-bin

max_binlog_size=500M
binlog_cache_size=128K
binlog-do-db=P2Psite,apollodb,hermes,hermesPro,p2psite
binlog-ignore-db=mysql
log-slave-updates

expire_logs_days = 7

binlog_format="MIXED"


datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock

# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

给 /home/mysql 更改组
chown -R mysql:mysql /home/mysql

从库配置

slave-skip-errors=1007,1008,1053,1062,1213,1158,1159
master-connect-retry=30

进入从库数据并执行一下sql预计

stop slave;

change master to

master_host='192.168.3.108',

master_user='slave_repl',

master_password='slave_repl_mysql',

master_port=3306,

master_log_file='mysql-bin.000002',

master_log_pos=154;
start slave;

常规sql语句
主库

##查询主库状态
show master STATUS;

##锁定主库的表
FLUSH TABLES WITH READ LOCK;


##解锁主库表
UNLOCK TABLES;

SHOW PROCESSLIST;


##导出数据
mysqldump -uroot -p -q -e -t apollodb > apollodb.sql

从库

##在从库上执行同步语句 执行以下语句:
stop slave;
change master to
master_host='192.168.3.108',
master_user='slave_repl',
master_password='slave_repl_mysql',
master_port=3306,
master_log_file='mysql-bin.000003',
master_log_pos=154;
start slave;



#禁止外键约束
SET FOREIGN_KEY_CHECKS=0;

#开启外键约束
SET FOREIGN_KEY_CHECKS=1;


SHOW PROCESSLIST;

SHOW SLAVE STATUS;

你可能感兴趣的:(Mysql 主从同步配置)