千家信息网

MyCat分库分表--实战03--全局表

发表于:2025-01-20 作者:千家信息网编辑
千家信息网最后更新 2025年01月20日,项目环境:192.168.8.30 mycat192.168.8.31 node1192.168.8.32 node2192.168.8.33 node3三个节点MySQL均为单实例一、配置schem
千家信息网最后更新 2025年01月20日MyCat分库分表--实战03--全局表

项目环境:

192.168.8.30 mycat

192.168.8.31 node1

192.168.8.32 node2

192.168.8.33 node3

三个节点MySQL均为单实例

一、配置schema.xml

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

二、配置server.xml

                mysql                mycatdb

三、创建测试库

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;

四、启动mycat

/usr/local/mycat/bin/mycat start

查看mycat日志

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

五、登录MySQL查看全局表

mysql -uroot -pmysql -P8066 -h292.168.8.30
mysql> use mycatdbReading 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 |+-------------------+| user01            || user02            |+-------------------+2 rows in set (0.01 sec)mysql> drop table user02;ERROR 1105 (HY000): Unknown table 'testdb11.user02'mysql> select * from user02;ERROR 1146 (HY000): Table 'testdb01.user02' doesn't existmysql> drop table if exists user02;Query OK, 0 rows affected, 1 warning (0.40 sec

建表user02并插入三条记录

mysql> create table user02(    ->    id INT(10) NOT NULL AUTO_INCREMENT,    ->    name varchar(30),    ->    PRIMARY KEY ( id )    -> );Query OK, 0 rows affected (1.74 sec)mysql> insert into user02(name) values('steven');Query OK, 1 row affected (0.29 sec)mysql> insert into user02(name) values('steven');Query OK, 1 row affected (0.33 sec)mysql> insert into user02(name) values('steven');Query OK, 1 row affected (0.31 sec)

六、数据验证

node1

mysql> select * from testdb01.user02;+----+--------+| id | name   |+----+--------+|  1 | steven ||  2 | steven ||  3 | steven |+----+--------+3 rows in set (0.00 sec)mysql> select * from testdb05.user02;+----+--------+| id | name   |+----+--------+|  1 | steven ||  2 | steven ||  3 | steven |+----+--------+3 rows in set (0.01 sec)mysql> select * from testdb12.user02;+----+--------+| id | name   |+----+--------+|  1 | steven ||  2 | steven ||  3 | steven |+----+--------+3 rows in set (0.00 sec)

node2

mysql> select * from testdb16.user02;+----+--------+| id | name   |+----+--------+|  1 | steven ||  2 | steven ||  3 | steven |+----+--------+3 rows in set (0.00 sec)mysql> select * from testdb19.user02;+----+--------+| id | name   |+----+--------+|  1 | steven ||  2 | steven ||  3 | steven |+----+--------+3 rows in set (0.00 sec)mysql> select * from testdb22.user02;+----+--------+| id | name   |+----+--------+|  1 | steven ||  2 | steven ||  3 | steven |+----+--------+3 rows in set (0.00 sec)

node3

mysql> select * from testdb25.user02;+----+--------+| id | name   |+----+--------+|  1 | steven ||  2 | steven ||  3 | steven |+----+--------+3 rows in set (0.00 sec)mysql> select * from testdb30.user02;+----+--------+| id | name   |+----+--------+|  1 | steven ||  2 | steven ||  3 | steven |+----+--------+3 rows in set (0.00 sec)mysql> select * from testdb33.user02;+----+--------+| id | name   |+----+--------+|  1 | steven ||  2 | steven ||  3 | steven |+----+--------+

可以看到每个node的每个database存的数据都一模一样,全局表验证完毕。



0