千家信息网

MyCat分库分表实例教程

发表于:2025-01-20 作者:千家信息网编辑
千家信息网最后更新 2025年01月20日,这篇文章主要介绍"MyCat分库分表实例教程",在日常操作中,相信很多人在MyCat分库分表实例教程问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答"MyCat分库分表实例
千家信息网最后更新 2025年01月20日MyCat分库分表实例教程

这篇文章主要介绍"MyCat分库分表实例教程",在日常操作中,相信很多人在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;create database testdb04;create database testdb05;create database testdb06;create database testdb07;create database testdb08;create database testdb09;create database testdb10;create database testdb11;create database testdb12;

node2

create database testdb13;create database testdb14;create database testdb15;create database testdb16;create database testdb17;create database testdb18;create database testdb19;create database testdb20;create database testdb21;create database testdb22;create database testdb23;create database testdb24;

node3

create database testdb25;create database testdb26;create database testdb27;create database testdb28;create database testdb29;create database testdb30;create database testdb31;create database testdb32;create database testdb33;create database testdb34;create database testdb35;create database testdb36;

二、配置schema.xml

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

三、配置rule.xml

                                        adddate                        partbymonth                               yyyy-MM-dd                 2016-01-01 

四、启动mycat

/usr/local/mycat/bin/mycat start

查看mycat日志

STATUS | wrapper  | 2018/11/22 19:52:42 | --> Wrapper Started as DaemonSTATUS | wrapper  | 2018/11/22 19:52:42 | Launching a JVM...INFO   | jvm 1    | 2018/11/22 19:52:42 | OpenJDK 64-Bit Server VM warning: ignoring option MaxPermSize=64M; support was removed in 8.0INFO   | jvm 1    | 2018/11/22 19:52:44 | Wrapper (Version 3.2.3) http://wrapper.tanukisoftware.orgINFO   | jvm 1    | 2018/11/22 19:52:44 |   Copyright 1999-2006 Tanuki Software, Inc.  All Rights Reserved.INFO   | jvm 1    | 2018/11/22 19:52:44 | INFO   | jvm 1    | 2018/11/22 19:52:49 | 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.03 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 |+-------------------+| user04            || user05            || user06            |+-------------------+3 rows in set (0.01 sec)mysql> select * from user06;ERROR 1105 (HY000): Table 'testdb36.user06' doesn't existmysql> drop table if exists user06;Query OK, 0 rows affected, 1 warning (0.38 sec)mysql> create table user06(    -> id int not null auto_increment,    -> name varchar(64),    -> adddate datetime,    -> primary key(id)    -> );Query OK, 0 rows affected (1.73 sec)

六、插入测试数据

insert into user06(id,name,adddate) values(1,'steven','2016-05-09 12:32:12');insert into user06(id,name,adddate) values(2,'steven','2016-09-09 12:32:12');insert into user06(id,name,adddate) values(3,'steven','2016-12-09 12:32:12');insert into user06(id,name,adddate) values(4,'steven','2017-05-09 12:32:12');insert into user06(id,name,adddate) values(5,'steven','2017-06-09 12:32:12');insert into user06(id,name,adddate) values(6,'steven','2017-07-09 12:32:12');insert into user06(id,name,adddate) values(7,'steven','2018-05-09 12:32:12');insert into user06(id,name,adddate) values(8,'steven','2018-05-09 12:32:12');insert into user06(id,name,adddate) values(9,'steven','2018-08-09 12:32:12');insert into user06(id,name,adddate) values(10,'steven','2018-12-09 12:32:12');

七、验证数据

node1

mysql> select * from testdb01.user06;Empty set (0.00 sec)mysql> select * from testdb02.user06;Empty set (0.00 sec)mysql> select * from testdb03.user06;Empty set (0.00 sec)mysql> select * from testdb04.user06;Empty set (0.01 sec)mysql> select * from testdb05.user06;+----+--------+---------------------+| id | name   | adddate             |+----+--------+---------------------+|  1 | steven | 2016-05-09 12:32:12 |+----+--------+---------------------+1 row in set (0.00 sec)mysql> select * from testdb06.user06;Empty set (0.01 sec)mysql> select * from testdb07.user06;Empty set (0.01 sec)mysql> select * from testdb08.user06;Empty set (0.01 sec)mysql> select * from testdb09.user06;+----+--------+---------------------+| id | name   | adddate             |+----+--------+---------------------+|  2 | steven | 2016-09-09 12:32:12 |+----+--------+---------------------+1 row in set (0.00 sec)mysql> select * from testdb10.user06;Empty set (0.00 sec)mysql> select * from testdb11.user06;Empty set (0.00 sec)mysql> select * from testdb12.user06;+----+--------+---------------------+| id | name   | adddate             |+----+--------+---------------------+|  3 | steven | 2016-12-09 12:32:12 |+----+--------+---------------------+1 row in set (0.00 sec)

node2

mysql> select * from testdb13.user06;Empty set (0.00 sec)mysql> select * from testdb14.user06;Empty set (0.00 sec)mysql> select * from testdb15.user06;Empty set (0.00 sec)mysql> select * from testdb16.user06;Empty set (0.00 sec)mysql> select * from testdb17.user06;+----+--------+---------------------+| id | name   | adddate             |+----+--------+---------------------+|  4 | steven | 2017-05-09 12:32:12 |+----+--------+---------------------+1 row in set (0.00 sec)mysql> select * from testdb18.user06;+----+--------+---------------------+| id | name   | adddate             |+----+--------+---------------------+|  5 | steven | 2017-06-09 12:32:12 |+----+--------+---------------------+1 row in set (0.01 sec)mysql> select * from testdb19.user06;+----+--------+---------------------+| id | name   | adddate             |+----+--------+---------------------+|  6 | steven | 2017-07-09 12:32:12 |+----+--------+---------------------+1 row in set (0.00 sec)mysql> select * from testdb20.user06;Empty set (0.01 sec)mysql> select * from testdb21.user06;Empty set (0.00 sec)mysql> select * from testdb22.user06;Empty set (0.00 sec)mysql> select * from testdb23.user06;Empty set (0.00 sec)mysql> select * from testdb24.user06;Empty set (0.01 sec)

node3

mysql> select * from testdb25.user06;Empty set (0.00 sec)mysql> select * from testdb26.user06;Empty set (0.00 sec)mysql> select * from testdb27.user06;Empty set (0.00 sec)mysql> select * from testdb28.user06;Empty set (0.01 sec)mysql> select * from testdb29.user06;+----+--------+---------------------+| id | name   | adddate             |+----+--------+---------------------+|  7 | steven | 2018-05-09 12:32:12 ||  8 | steven | 2018-05-09 12:32:12 |+----+--------+---------------------+2 rows in set (0.00 sec)mysql> select * from testdb30.user06;Empty set (0.01 sec)mysql> select * from testdb31.user06;Empty set (0.01 sec)mysql> select * from testdb32.user06;+----+--------+---------------------+| id | name   | adddate             |+----+--------+---------------------+|  9 | steven | 2018-08-09 12:32:12 |+----+--------+---------------------+1 row in set (0.00 sec)mysql> select * from testdb33.user06;Empty set (0.00 sec)mysql> select * from testdb34.user06;Empty set (0.01 sec)mysql> select * from testdb35.user06;Empty set (0.01 sec)mysql> select * from testdb36.user06;+----+--------+---------------------+| id | name   | adddate             |+----+--------+---------------------+| 10 | steven | 2018-12-09 12:32:12 |+----+--------+---------------------+1 row in set (0.00 sec)

到此,关于"MyCat分库分表实例教程"的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注网站,小编会继续努力为大家带来更多实用的文章!

0