千家信息网

MyCat怎么实现分库分表

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

四、配置server.xml

                mysql                mycatdb

五、启动mycat

/usr/local/mycat/bin/mycat start

查看mycat日志

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

六、登录MySQL查看逻辑表

mysql -uroot -pmysql -P8066 -h292.168.8.30
mysql> show databases;+----------+| DATABASE |+----------+| mycatdb  |+----------+1 row in set (0.00 sec)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            || user04            |+-------------------+6 rows in set (0.01 sec)mysql> select * from user04;ERROR 1105 (HY000): Table 'testdb03.user04' doesn't existmysql> drop table if exists user04;Query OK, 0 rows affected, 1 warning (0.15 sec)mysql> create table user04 (    -> id int not null auto_increment,    -> name varchar(64),    -> primary key (id)    -> );Query OK, 0 rows affected (0.61 sec)

七、插入测试数据

insert into user04(id,name) values(1,'steven');insert into user04(id,name) values(2,'steven');insert into user04(id,name) values(3,'steven');insert into user04(id,name) values(4,'steven');insert into user04(id,name) values(5,'steven');insert into user04(id,name) values(6,'steven');insert into user04(id,name) values(7,'steven');insert into user04(id,name) values(8,'steven');insert into user04(id,name) values(9,'steven');insert into user04(id,name) values(10,'steven');insert into user04(id,name) values(11,'steven');insert into user04(id,name) values(12,'steven');insert into user04(id,name) values(13,'steven');insert into user04(id,name) values(14,'steven');insert into user04(id,name) values(15,'steven');insert into user04(id,name) values(16,'steven');insert into user04(id,name) values(17,'steven');insert into user04(id,name) values(18,'steven');insert into user04(id,name) values(19,'steven');insert into user04(id,name) values(20,'steven');insert into user04(id,name) values(21,'steven');insert into user04(id,name) values(22,'steven');insert into user04(id,name) values(23,'steven');insert into user04(id,name) values(24,'steven');insert into user04(id,name) values(25,'steven');insert into user04(id,name) values(26,'steven');insert into user04(id,name) values(27,'steven');insert into user04(id,name) values(28,'steven');insert into user04(id,name) values(29,'steven');insert into user04(id,name) values(30,'steven');insert into user04(id,name) values(31,'steven');insert into user04(id,name) values(32,'steven');insert into user04(id,name) values(33,'steven');insert into user04(id,name) values(34,'steven');insert into user04(id,name) values(35,'steven');insert into user04(id,name) values(36,'steven');insert into user04(id,name) values(37,'steven');insert into user04(id,name) values(38,'steven');insert into user04(id,name) values(39,'steven');insert into user04(id,name) values(40,'steven');insert into user04(id,name) values(41,'steven');insert into user04(id,name) values(42,'steven');insert into user04(id,name) values(43,'steven');insert into user04(id,name) values(44,'steven');insert into user04(id,name) values(45,'steven');insert into user04(id,name) values(46,'steven');insert into user04(id,name) values(47,'steven');insert into user04(id,name) values(48,'steven');insert into user04(id,name) values(49,'steven');insert into user04(id,name) values(50,'steven');

八、验证数据

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

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

node1

mysql> select * from testdb01.user04;+----+--------+| id | name   |+----+--------+|  8 | steven || 14 | steven || 16 | steven || 17 | steven || 34 | steven || 49 | steven |+----+--------+6 rows in set (0.00 sec)mysql> select * from testdb02.user04;+----+--------+| id | name   |+----+--------+|  9 | steven || 10 | steven || 44 | steven || 45 | steven || 46 | steven || 48 | steven |+----+--------+6 rows in set (0.00 sec)mysql> select * from testdb03.user04;+----+--------+| id | name   |+----+--------+| 11 | steven || 24 | steven || 33 | steven || 35 | steven || 40 | steven |+----+--------+5 rows in set (0.00 sec)

node2

mysql> select * from testdb13.user04;+----+--------+| id | name   |+----+--------+| 20 | steven || 25 | steven || 38 | steven || 39 | steven |+----+--------+4 rows in set (0.00 sec)mysql> select * from testdb14.user04;+----+--------+| id | name   |+----+--------+|  1 | steven || 41 | steven || 50 | steven |+----+--------+3 rows in set (0.01 sec)mysql> select * from testdb15.user04;+----+--------+| id | name   |+----+--------+| 12 | steven || 18 | steven || 32 | steven || 36 | steven |+----+--------+4 rows in set (0.00 sec)

node3

mysql> select * from testdb25.user04;+----+--------+| id | name   |+----+--------+|  6 | steven || 13 | steven || 19 | steven || 23 | steven || 27 | steven || 28 | steven || 29 | steven || 31 | steven || 37 | steven |+----+--------+9 rows in set (0.00 sec)mysql> select * from testdb26.user04;+----+--------+| id | name   |+----+--------+|  4 | steven ||  5 | steven || 15 | steven || 22 | steven || 42 | steven |+----+--------+5 rows in set (0.00 sec)mysql> select * from testdb27.user04;+----+--------+| id | name   |+----+--------+|  2 | steven ||  3 | steven ||  7 | steven || 21 | steven || 26 | steven || 30 | steven || 43 | steven || 47 | steven |+----+--------+8 rows in set (0.00 sec)

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

0