mysql 5.5 master slave搭建
2015-11-03 11:03
302 查看
1、环境
centos 7
2、配置master
修改/etc/my.cnf增加
3、master创建一个复制用户
重启master
4、配置slave
修改/etc/my.cnf增加
重启slave
5、master 刷新所有表,并阻止写入
6、mysqldump导出所有需要复制的数据库
7、解锁之前锁定的表
8、把备份文件拷贝到从库
9、从库执行:
10、连接master和slave
11、查看复制状态
12、问题
12.1如果出现Last_IO_Error: error connecting to master
原因:
1、主库防火墙是否关闭
service firewalld status
关闭防火墙
systemctl stop firewalld.service
禁止开机启动
systemctl disable firewalld.service
centos 7
2、配置master
修改/etc/my.cnf增加
[mysqld] log-bin = master-bin log-bin-index = master-bin.index server-id = 1
3、master创建一个复制用户
CREATE USER repl_user; GRANT REPLICATION SLAVE ON *.* TO repl_user IDENTIFIED BY '123456';
重启master
4、配置slave
修改/etc/my.cnf增加
[mysqld] server-id = 2 relay-log-index = slave-relay-bin.index relay-log slave-relay-bin
重启slave
5、master 刷新所有表,并阻止写入
mysql> flush tables with read lock; 当前二进制日志的文件名和位置 mysql> show master status; +------------------+----------+--------------+------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | +------------------+----------+--------------+------------------+ | mysql-bin.000006 | 107 | | | +------------------+----------+--------------+------------------+ 1 row in set (0.00 sec)
6、mysqldump导出所有需要复制的数据库
mysqldump -uroot -pmysql --all-databases --lock-all-tables >dbdump.db
7、解锁之前锁定的表
mysql> unlock tables; Query OK, 0 rows affected (0.00 sec)
8、把备份文件拷贝到从库
[root@localhost opt]# scp dbdump.db root@192.168.137.106:/opt/
9、从库执行:
mysql> stop slave; Query OK, 0 rows affected, 1 warning (0.00 sec) 导入文件 source /opt/dbdump.db
10、连接master和slave
CHANGE MASTER TO MASTER_HOST = '192.168.137.105', MASTER_PORT = 3306, MASTER_USER = 'repl_user', MASTER_PASSWORD = '123456', MASTER_LOG_FILE = 'mysql-bin.000006', MASTER_LOG_POS = 107; START SLAVE;
11、查看复制状态
show slave status\G
12、问题
12.1如果出现Last_IO_Error: error connecting to master
原因:
1、主库防火墙是否关闭
service firewalld status
关闭防火墙
systemctl stop firewalld.service
禁止开机启动
systemctl disable firewalld.service
相关文章推荐
- mysql innobackupex备份恢复
- MySQL主从服务器数据一致性的核对与修复
- mysql常用查询语句
- MySQL 5.7.9 免安装配置
- mysql 远程账户
- MySql优化配置
- MySQL的查询优化
- MySql中分组简介
- mysqli扩展库应用---批量执行sql语句
- mysql 定时任务
- MySql导入导出数据库命令
- mysql扩展中常用函数
- mysql 从库I/O及SQL thread 状态解释
- 为什么要 MySQL 迁移到 Maria DB
- MySQL
- MySQL性能优化的最佳21条经验
- mysql之my.cnf
- 解决Mysql "is marked as crashed and should be repaired"的故障
- 安装mysql 5.7.9绿色版遇到的问题记录
- MySQL存储过程详解 mysql 存储过程