mysql 5.6主从配置
mysql主从
先配置主
1、
mysql机器 create user repl;
GRANT REPLICATION SLAVE ON *.* TO 'repl'@'192.168.1.244' IDENTIFIED BY '666666';
FLUSH PRIVILEGES;
2、
my.conf
server-id=1
log_bin = mysql-bin
log-bin-index=mysql-bin.index
sync_binlog=1
binlog_format=mixed
binlog-do-db = mall //同步数据库
binlog-do-db = cms
binlog-do-db = ucenter
binlog-ignore-db = mysql
binlog-ignore-db = performance_schema
binlog-ignore-db = information_schema
binlog_checksum=NONE
3、
service mysqld restart
进入mysql
SHOW MASTER STATUS;
返回
+------------------+----------+------------------+---------------------------------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+------------------+---------------------------------------------+-------------------+
| mysql-bin.000003 | 120 | mall,cms,ucenter | mysql,performance_schema,information_schema | |
+------------------+----------+------------------+---------------------------------------------+-------------------+
就ok了
再配置从
1、
my.conf
log-bin=mysql-bin
server-id=2
relay-log-index = slave-relay-bin.index
relay-log = slave-relay-bin
sync_master_info = 1
sync_relay_log = 1
sync_relay_log_info = 1
service mysqld restart
2、
手动倒入库,先在从库上建立数据库
然后在主库上
flush tables with read lock;
mysqldump出来
然后从库source
3、
mysql> change master to master_host='192.168.1.243',master_user='repl',master_password='666666', master_log_file='mysql-bin.000003',master_log_pos=120
start slave;
show slave status\G;
返回
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
就对了
主库打开
UNLOCK TABLES;
SHOW SLAVE STATUS;
另外,从库配置只读。
show global variables like "%read_only%";
set global read_only=1;
只保留1天日志
set global expire_logs_days=1;
查询
show variables like '%max_binlog_size%'
set global max_binlog_size=500;
后面会自动叠加文件,类似这样。
| mysql-bin.000001 | 18214 |
| mysql-bin.000002 | 4147 |
| mysql-bin.000003 | 2124 |
SHOW MASTER LOGS;
最新内容
- Linux系统下systemctl常用命令以及service文件配置
- CI PHP7 session 不能读取的问题
- centos 7.4 基本配置
- mysqldump导入导出数据库总结
- Linux下的tar压缩解压缩常用命令
- 查看 SELinux状态、临时关闭SELinux、永久关闭SELinux
- centos6.8 yum安装mysql 5.6
- CentOS之7与6的区别2
- CentOS之7与6的区别1
- Mysql 忘记root密码的完美解决方法
- 输入密码登录,Linux scp (rsync)设置nohup后台运行
- ubantu zabbix部署——安装配置zabbix agent详解
- Zabbix客户端(agent端口)安装配置
- CentOS 7添加开机启动服务/脚本
- 阿里云机器配置 centos 6.8