mysql海量数据存储和解决方案_MySQL海量数据存储与优化

本文介绍了如何实现MySQL的主从搭建,包括两组一主两从架构的详细配置步骤,以及在遇到主从同步问题时的解决策略,如错误1236的处理方法,旨在优化海量数据的存储和处理。
摘要由CSDN通过智能技术生成

一、实现MySQL分库和读写分离

MySQL主从搭建

两组 一主两从架构(6台主机:2主,4从)

第一组:192.168.47.10(主)、192.168.47.11(从)和192.168.47.12(从)

第二组:192.168.47.14(主)、192.168.47.15(从)和192.168.47.16(从)

mysql 版本

修改MySQL的配置文件my.cnf

vim /etc/my.cnf

配置虚拟机的固定IP

vi /etc/sysconfig/network-scripts/ifcfg-ens33

重启网卡ip才能生效

service network restart

主库给从库授权

在MySQL命令行执行如下命令:

#开启复制功能

grant replication slave on *.* to 'root'@'%' identified by '123456';

#开启远程登录功能

grant all privileges on *.* to 'root'@'%' identified by '123456';

刷新权限

flush privileges;

重启服务

service mysql restart

查看同步状态

mysql> show master status;

Empty set (0.00 sec)

将从库的salve地址 指向 master

即在192.168.47.15和192.168.47.16执行同步复制

mysql> change master to master_host='192.168.47.14',master_port=3306,master_user='root',master_password='123456',master_log_file='mysqlbinlog.000001',master_log_pos=869;

注意: master_log_file 指的是主库的当前binlog文件的名称,master_log_pos指的是当前主库binlog的位置。 主库的防火墙必须关闭,才能连接上。 开启从库

1:查看防火状态

systemctl status firewalld

service iptables status

2:暂时关闭防火墙

systemctl stop firewalld

service iptables stop

3:永久关闭防火墙

systemctl disable firewalld

chkconfig iptables off

4:重启防火墙

systemctl enable firewalld

service iptables restart

5:永久关闭后重启

//暂时还没有试过

chkconfig iptables on

查看从库的状态

mysql> show slave status \G;

如果是Slave_SQL_Running:no:

解决办法如下

stop slave;

SET GLOBAL SQL_SLAVE_SKIP_COUNTER=1; START SLAVE;

start slave;

show slave status\G

Slave_IO_Running: No

解决问题的思路:

1. 找到mysql配置的这个文件/etc/my.cnf

2. 在文件中找到mysql错误异常日志文件的路径,我配置的是log-error=/var/log/mysqld.log

3. 编辑/var/log/mysqld.log文件

4. 查看具体异常信息

异常信息:

[ERROR] Slave I/O for channel ‘’: Fatal error: The slave I

/O thread stops because master and slave have equal MySQL server UUIDs; these UUIDs must

be different for replication to work. Error_code: 1593

问题定位:由于uuid相同,而导致触发此异常

解决方案:把uuid修改即可

另一种原因 :没能从master读到文件了的内容

Error reading packet from server for channel '': bogus data in log event; the first event 'mysqlbinlog.000001' at 869, the last event read from './mysqlbinlog.000001' at 123, the last byte read from './mysqlbinlog.000001' at 888. (server_errno=1236)

2021-01-28T17:51:49.992665Z 15 [ERROR] Slave I/O for channel '': Got fatal error 1236 from master when reading data from binary log: 'bogus data in log event; the first event 'mysqlbinlog.000001' at 869, the last event read from './mysqlbinlog.000001' at 123, the last byte read from './mysqlbinlog.000001' at 888.', Error_code: 1236

解决方法:

master端:

mysql> flush logs;

Query OK, 0 rows affected (0.02 sec)

mysql> show master status;

+---------------------+----------+--------------+------------------+-------------------+

| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |

+---------------------+----------+--------------+------------------+-------------------+

| dbmaster-bin.000005 | 120 | | | |

+---------------------+----------+--------------+------------------+-------------------+

1 row in set (0.00 sec)

记住file和position这两个选项

slave端:

mysql> stop slave;

Query OK, 0 rows affected (0.01 sec)

mysql> change master to master_log_file ='dbmaster-bin.000005',master_log_pos=120;

Query OK, 0 rows affected (0.01 sec)

mysql> start slave;

Query OK, 0 rows affected (0.00 sec)

show slave status\G;

再次查看状态就会发现成功了。

验证主从

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值