千家信息网

MyCat怎么分库分表

发表于:2024-11-24 作者:千家信息网编辑
千家信息网最后更新 2024年11月24日,本篇内容介绍了"MyCat怎么分库分表"的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!项目环境:192
千家信息网最后更新 2024年11月24日MyCat怎么分库分表

本篇内容介绍了"MyCat怎么分库分表"的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!

项目环境:

192.168.8.30 mycat

192.168.8.31 node1

192.168.8.32 node2

192.168.8.33 node3

三个节点MySQL均为单实例

一、创建测试库

node1

create database testdb01;create database testdb02;create database testdb03;

node2

create database testdb13;create database testdb14;create database testdb15;

node3

create database testdb25;create database testdb26;create database testdb27;

二、配置schema.xml

                    
select user() select user() select user()

三、配置rule.xml

                                                id                        autopartition-long-user03                                                       autopartition-long-user03.txt                0        

四、配置autopartition-long-user03.txt

1-10=011-20=121-30=231-40=341-50=451-60=561-70=671-80=781-10000=8

五、配置server.xml

                mysql                mycatdb

六、启动mycat

/usr/local/mycat/bin/mycat start

查看mycat日志

STATUS | wrapper  | 2018/11/22 15:27:14 | --> Wrapper Started as DaemonSTATUS | wrapper  | 2018/11/22 15:27:14 | Launching a JVM...INFO   | jvm 1    | 2018/11/22 15:27:14 | OpenJDK 64-Bit Server VM warning: ignoring option MaxPermSize=64M; support was removed in 8.0INFO   | jvm 1    | 2018/11/22 15:27:16 | Wrapper (Version 3.2.3) http://wrapper.tanukisoftware.orgINFO   | jvm 1    | 2018/11/22 15:27:16 |   Copyright 1999-2006 Tanuki Software, Inc.  All Rights Reserved.INFO   | jvm 1    | 2018/11/22 15:27:16 | INFO   | jvm 1    | 2018/11/22 15:27:20 | MyCAT Server startup successfully. see logs in logs/mycat.log

七、登录MySQL并查看逻辑表

mysql> use mycatdb;Reading table information for completion of table and column namesYou can turn off this feature to get a quicker startup with -ADatabase changedmysql> show tables;+-------------------+| Tables in mycatdb |+-------------------+| order01           || orderdetail01     || user01            || user02            || user03            |+-------------------+5 rows in set (0.00 sec)mysql> mysql> mysql> drop table if exists user03;Query OK, 0 rows affected, 1 warning (0.23 sec)mysql> create table user03 (    -> id int not null auto_increment,    -> name varchar(64),    -> primary key (id)    -> );Query OK, 0 rows affected (0.43 sec)

八、插入测试数据

共插入50条数据

insert into user03(id,name) values(1,'steven');insert into user03(id,name) values(2,'steven');insert into user03(id,name) values(3,'steven');insert into user03(id,name) values(4,'steven');insert into user03(id,name) values(5,'steven');insert into user03(id,name) values(11,'steven');insert into user03(id,name) values(12,'steven');insert into user03(id,name) values(13,'steven');insert into user03(id,name) values(14,'steven');insert into user03(id,name) values(15,'steven');insert into user03(id,name) values(21,'steven');insert into user03(id,name) values(22,'steven');insert into user03(id,name) values(23,'steven');insert into user03(id,name) values(24,'steven');insert into user03(id,name) values(25,'steven');insert into user03(id,name) values(31,'steven');insert into user03(id,name) values(32,'steven');insert into user03(id,name) values(33,'steven');insert into user03(id,name) values(34,'steven');insert into user03(id,name) values(35,'steven');insert into user03(id,name) values(41,'steven');insert into user03(id,name) values(42,'steven');insert into user03(id,name) values(43,'steven');insert into user03(id,name) values(44,'steven');insert into user03(id,name) values(45,'steven');insert into user03(id,name) values(51,'steven');insert into user03(id,name) values(52,'steven');insert into user03(id,name) values(53,'steven');insert into user03(id,name) values(54,'steven');insert into user03(id,name) values(55,'steven');insert into user03(id,name) values(61,'steven');insert into user03(id,name) values(62,'steven');insert into user03(id,name) values(63,'steven');insert into user03(id,name) values(64,'steven');insert into user03(id,name) values(65,'steven');insert into user03(id,name) values(71,'steven');insert into user03(id,name) values(72,'steven');insert into user03(id,name) values(73,'steven');insert into user03(id,name) values(74,'steven');insert into user03(id,name) values(75,'steven');insert into user03(id,name) values(81,'steven');insert into user03(id,name) values(82,'steven');insert into user03(id,name) values(83,'steven');insert into user03(id,name) values(84,'steven');insert into user03(id,name) values(85,'steven');insert into user03(id,name) values(91,'steven');insert into user03(id,name) values(92,'steven');insert into user03(id,name) values(93,'steven');insert into user03(id,name) values(94,'steven');insert into user03(id,name) values(95,'steven');

九、数据验证

三个node只在testdb01-03,testdb13-15,testdb25-27,所以除了这9个物理库之外,其他库查不到分片。

下面在三个node分别验证出分片信息:

node1

mysql> select count(*) from testdb01.user03;+----------+| count(*) |+----------+|        5 |+----------+1 row in set (0.00 sec)mysql> select count(*) from testdb02.user03;+----------+| count(*) |+----------+|        5 |+----------+1 row in set (0.00 sec)mysql> select count(*) from testdb03.user03;+----------+| count(*) |+----------+|        5 |+----------+1 row in set (0.00 sec)

node2

mysql> select count(*) from testdb13.user03;+----------+| count(*) |+----------+|        5 |+----------+1 row in set (0.00 sec)mysql> select count(*) from testdb14.user03;+----------+| count(*) |+----------+|        5 |+----------+1 row in set (0.00 sec)mysql> select count(*) from testdb15.user03;+----------+| count(*) |+----------+|        5 |+----------+1 row in set (0.00 sec)

node3

mysql> select count(*) from testdb25.user03;+----------+| count(*) |+----------+|        5 |+----------+1 row in set (0.00 sec)mysql> select count(*) from testdb26.user03;+----------+| count(*) |+----------+|        5 |+----------+1 row in set (0.00 sec)mysql> select count(*) from testdb27.user03;+----------+| count(*) |+----------+|       10 |+----------+1 row in set (0.00 sec)

"MyCat怎么分库分表"的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注网站,小编将为大家输出更多高质量的实用文章!

0