主从复制2——拥有海量数据主服务器的主从复制模型详细实现;
发表于:2025-11-10 作者:千家信息网编辑
千家信息网最后更新 2025年11月10日,基本策略:此时需要在主服务器上先完全备份,还原到从服务器;接着开启主从复制;如果直接使用主从复制,那么主从服务器的压力很大;主服务器数据全备份操作:[root@master ~]$mysqldump
千家信息网最后更新 2025年11月10日主从复制2——拥有海量数据主服务器的主从复制模型详细实现;
基本策略:
此时需要在主服务器上先完全备份,还原到从服务器;接着开启主从复制;如果直接使用主从复制,那么主从服务器的压力很大;
主服务器数据全备份操作:
[root@master ~]$mysqldump -A -F --single-transaction --master-data=1 > all.sql
主服务器模拟修改操作:
MariaDB [(none)]> create database wangdb1;Query OK, 1 row affected (0.01 sec)MariaDB [(none)]> show master logs;+--------------------+-----------+| Log_name | File_size |+--------------------+-----------+| mariadb-bin.000001 | 8217 || mariadb-bin.000002 | 555 || mariadb-bin.000003 | 334 |+--------------------+-----------+3 rows in set (0.00 sec)[root@master ~]$less all.sqlCHANGE MASTER TO MASTER_LOG_FILE='mariadb-bin.000003', MASTER_LOG_POS=245;
主服务器配置:
[root@slave ~]$vim /etc/my.cnf[mysqld]datadir=/var/lib/mysqlsocket=/var/lib/mysql/mysql.sock# Disabling symbolic-links is recommended to prevent assorted security riskssymbolic-links=0# Settings user and group are ignored when systemd is used.innodb_file_per_tableserver_id=2
从服务器数据还原:
[root@master ~]$scp all.sql 192.168.27.17:~[root@slave ~]$mysql < all.sql
从服务器开启主从复制:
MariaDB [(none)]> CHANGE MASTER TO -> MASTER_HOST='192.168.27.7', -> MASTER_USER='repluser', -> MASTER_PASSWORD='centos', -> MASTER_LOG_FILE='mariadb-bin.000003', -> MASTER_LOG_POS=245;Query OK, 0 rows affected (0.01 sec)MariaDB [(none)]> start slave;Query OK, 0 rows affected (0.00 sec)MariaDB [(none)]> show slave status\G*************************** 1. row *************************** Slave_IO_State: Waiting for master to send event Master_Host: 192.168.27.7 Master_User: repluser Master_Port: 3306 Connect_Retry: 60 Master_Log_File: mariadb-bin.000003 Read_Master_Log_Pos: 334 Relay_Log_File: mariadb-relay-bin.000002 Relay_Log_Pos: 620 Relay_Master_Log_File: mariadb-bin.000003 Slave_IO_Running: Yes Slave_SQL_Running: Yes Replicate_Do_DB: Replicate_Ignore_DB: Replicate_Do_Table: Replicate_Ignore_Table: Replicate_Wild_Do_Table: Replicate_Wild_Ignore_Table: Last_Errno: 0 Last_Error: Skip_Counter: 0 Exec_Master_Log_Pos: 334 Relay_Log_Space: 916 Until_Condition: None Until_Log_File: Until_Log_Pos: 0 Master_SSL_Allowed: No Master_SSL_CA_File: Master_SSL_CA_Path: Master_SSL_Cert: Master_SSL_Cipher: Master_SSL_Key: Seconds_Behind_Master: 0Master_SSL_Verify_Server_Cert: No Last_IO_Errno: 0 Last_IO_Error: Last_SQL_Errno: 0 Last_SQL_Error: Replicate_Ignore_Server_Ids: Master_Server_Id: 11 row in set (0.00 sec)
从服务器数据一致性保证:
由于从服务器上的数据也是可以被删除的,所以为了保证数据的一致性,可以将只读属性打开;这种情况下,MySQL的root用户依然是可以修改删除的,只是对于普通用户生效; MariaDB [(none)]> show variables like 'read_only'; +---------------+-------+ | Variable_name | Value | +---------------+-------+ | read_only | OFF | +---------------+-------+ 1 row in set (0.00 sec)[root@slave ~]$vim /etc/my.cnf[mysqld]datadir=/var/lib/mysqlsocket=/var/lib/mysql/mysql.sock# Disabling symbolic-links is recommended to prevent assorted security riskssymbolic-links=0# Settings user and group are ignored when systemd is used.innodb_file_per_tableserver_id=2read_onlyMariaDB [(none)]> grant select,update,delete on *.* to test@'192.168.27.%' identified by 'centos';Query OK, 0 rows affected (0.00 sec)[root@master ~]$mysql -utest -pcentos -h292.168.27.17MariaDB [hellodb]> select * from students where age='22';+-------+---------------+-----+--------+---------+-----------+| StuID | Name | Age | Gender | ClassID | TeacherID |+-------+---------------+-----+--------+---------+-----------+| 1 | Shi Zhongyu | 22 | M | 2 | 3 || 2 | Shi Potian | 22 | M | 1 | 7 || 21 | Huang Yueying | 22 | F | 6 | NULL |+-------+---------------+-----+--------+---------+-----------+3 rows in set (0.00 sec)MariaDB [hellodb]> delete from students;ERROR 1290 (HY000): The MariaDB server is running with the --read-only option so it cannot execute this statement
服务器
服务
数据
主从
一致
一致性
备份
用户
保证
很大
普通
压力
只是
属性
情况
策略
配置
模型
海量
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
lol手游国际服连不上服务器
松江区正规数据库系统销售协议
高校服务器机房建设方案
大学生网络安全视频录制
利用数据库做图软件
oc创建数据库
数据库备份单个表的数据
白手起家服务器
国产顶级数据库
怎么连接服务器上的数据库
南充手机oa服务器
曙光服务器询价
网络安全 200 小学生
存储服务器功耗问题
商业app软件开发
软件开发质保期一般几年法律规定
域名解析连接数据库失败
用友数据库连接失败
王军税务网络安全
德洲扑克软件开发
成都精通网络技术有限公司向琛
docker怎么连主机数据库
新疆服务器机柜
千兆网络技术
淇县淘客app软件开发
存储服务器功耗问题
从哪些方面提升数据库的安全
提高mysql数据库性能
恒浩互联网科技(蒙自)有限公司
衢州mes软件开发