接上一篇:企业实战_12_MyCat水平扩展_分库分表
https://gblfy.blog.csdn.net/article/details/100059793
文章目录
- 一、复制链路停止
- 1. 清除冗余数据思路
- 2. 登录node4
- 3. 登录node3
- 4. 登录node2
- 二、删除冗余数据
- 2.1. 删除订单模块无关的表
- 2.2. 删除商品模块无关的表
- 2.3. 删除商品模块无关的表
- 三、验证
- 3.1. 验证逻辑库中的表数量
- 3.2. 查询逻辑表是否正常返回数据
一、复制链路停止
1. 清除冗余数据思路
首先,把node2、node3、node4的主从复制链路停止掉。
因为现在呢?虽然把莹莹切换到了mycat上,并且直接通过mycat对后端的3个物理数据库读写访问了,但是没实际上呢?
如果在node1上写数据,还会将数据同步到node2、node3、node4节点上,这样显然达不到垂直拆分的目的,垂直拆分呢,一方面想分担写的负载,另一方面呢,想减少每每个节点中数据数据量大小,要删除掉原本不属于该节点的数据。
2. 登录node4
104节点
# 登录数据库
mysql -uroot -p
Enter password: 123456# 停止复制链路
stop slave;# 清除主从同步的信息
reset slave all;# 查看链路,如果没有返回说明已经停止
show slave status \G
如下所示:
mysql> reset slave all;
Query OK, 0 rows affected (0.01 sec)mysql> show slave status \G
Empty set (0.00 sec)mysql>
3. 登录node3
103节点
# 登录数据库
mysql -uroot -p
Enter password: 123456# 停止复制链路
stop slave;# 清除主从同步的信息
reset slave all;# 查看链路,如果没有返回说明已经停止
show slave status \G
如下所示:
mysql> reset slave all;
Query OK, 0 rows affected (0.01 sec)mysql> show slave status \G
Empty set (0.00 sec)mysql>
4. 登录node2
102节点
# 登录数据库
mysql -uroot -p
Enter password: 123456# 停止复制链路
stop slave;# 清除主从同步的信息
reset slave all;# 查看链路,如果没有返回说明已经停止
show slave status \G
如下所示:
mysql> reset slave all;
Query OK, 0 rows affected (0.01 sec)mysql> show slave status \G
Empty set (0.00 sec)mysql>
二、删除冗余数据
2.1. 删除订单模块无关的表
登录node2操作102节点
# 登录mysql
mysql -uroot -p# 使用order_db数据库
use order_db;# 删除前查看表有哪些?
show tables;# 删除前他与order模块无关的表,删除之前建议先将表盒数据进行备份# 删除除了订单和仓配模块的表
drop table product_brand_info;
drop table product_category;
drop table product_comment;
drop table product_info;
drop table product_supplier_info;
drop table product_pic_info;drop table customer_balance_log;
drop table customer_inf;
drop table customer_level_inf;
drop table customer_login;
drop table customer_login_log;
drop table customer_point_log;# 删除后查看表有哪些?
show tables;mysql> show tables;
+---------------------+
| Tables_in_order_db |
+---------------------+
| order_cart |
| order_customer_addr |
| order_detail |
| order_master |
| region_info |
| serial |
| shipping_info |
| warehouse_info |
| warehouse_proudct |
+---------------------+
9 rows in set (0.00 sec)mysql>
2.2. 删除商品模块无关的表
登录node3操作103节点
# 登录数据库
mysql -uroot -p#使用指定数据库
use product_db;# 删除除了订单和仓配模块的表
drop table customer_balance_log;
drop table customer_inf;
drop table customer_level_inf;
drop table customer_login;
drop table customer_login_log;
drop table customer_point_log;drop table order_master;
drop table order_detail;
drop table order_cart;
drop table order_customer_addr;
drop table region_info;
drop table shipping_info;
drop table warehouse_info;
drop table warehouse_proudct;
drop table serial;# 删除后查看表有哪些?
show tables;mysql> show tables;
+-----------------------+
| Tables_in_product_db |
+-----------------------+
| product_brand_info |
| product_category |
| product_comment |
| product_info |
| product_pic_info |
| product_supplier_info |
+-----------------------+
6 rows in set (0.00 sec)mysql>
2.3. 删除商品模块无关的表
登录node4操作104节点
# 登录数据库
mysql -uroot -p#使用指定数据库
use customer_db;# 删除除了订单和仓配模块的表
drop table order_master;
drop table order_detail;
drop table order_cart;
drop table order_customer_addr;
drop table region_info;
drop table shipping_info;
drop table warehouse_info;
drop table warehouse_proudct;
drop table serial;drop table product_brand_info;
drop table product_category;
drop table product_comment;
drop table product_info;
drop table product_supplier_info;
drop table product_pic_info;# 删除后查看表有哪些?
show tables;mysql> show tables;
+-----------------------+
| Tables_in_customer_db |
+-----------------------+
| customer_balance_log |
| customer_inf |
| customer_level_inf |
| customer_login |
| customer_login_log |
| customer_point_log |
+-----------------------+
6 rows in set (0.00 sec)mysql>
三、验证
3.1. 验证逻辑库中的表数量
# 从任意节点重新登录mycat
mysql -uapp_imooc -p123456 -h192.168.92.101 -P8066# 使用imooc_db数据库
use imooc_db;# 查看逻辑库中的表
show tables;# 执行日志
mysql> show tables;
+-----------------------+
| Tables in imooc_db |
+-----------------------+
| customer_balance_log |
| customer_inf |
| customer_level_inf |
| customer_login |
| customer_login_log |
| customer_point_log |
| order_cart |
| order_customer_addr |
| order_detail |
| order_master |
| product_brand_info |
| product_category |
| product_comment |
| product_info |
| product_pic_info |
| product_supplier_info |
| region_info |
| shipping_info |
| warehouse_info |
| warehouse_proudct |
+-----------------------+
20 rows in set (0.00 sec)mysql> 从上面可以看出,imooc_db逻辑库库中的表并减少,说明,我们看到的实际是逻辑库中的表,,而非物理库中的表。
3.2. 查询逻辑表是否正常返回数据
# 查询逻辑库中的某个表,验证是否正常返回数据
mysql> select count(*) from region_info;
+--------+
| COUNT0 |
+--------+
| 1 |
+--------+
1 row in set (1.06 sec)mysql>
从上面可以看出,数据可以正常返回
下一篇:企业实战_14_MyCat跨分片查询_全局表
https://gblfy.blog.csdn.net/article/details/100059621