千家信息网

MyCat分库分表--实战01--垂直分库

发表于:2025-01-21 作者:千家信息网编辑
千家信息网最后更新 2025年01月21日,项目环境:192.168.8.30 mycat192.168.8.31 node1192.168.8.32 node2192.168.8.33 node3三个节点MySQL均为单实例一、创建测试数据n
千家信息网最后更新 2025年01月21日MyCat分库分表--实战01--垂直分库

项目环境:

192.168.8.30 mycat

192.168.8.31 node1

192.168.8.32 node2

192.168.8.33 node3

三个节点MySQL均为单实例

一、创建测试数据

node1

create database testdb1;create table testdb1.t01(name1 varchar(40),name2 varchar(40),name3 varchar(40));insert into testdb1.t01 values(@@hostname,@@hostname,@@hostname);create database testdb2;create table testdb2.t02(name1 varchar(40),name2 varchar(40),name3 varchar(40));insert into testdb2.t02 values(@@hostname,@@hostname,@@hostname);create database testdb3;create table testdb3.t03(name1 varchar(40),name2 varchar(40),name3 varchar(40));insert into testdb3.t03 values(@@hostname,@@hostname,@@hostname);

node2

create database testdb4;create table testdb4.t04(name1 varchar(40),name2 varchar(40),name3 varchar(40));insert into testdb4.t04 values(@@hostname,@@hostname,@@hostname);create database testdb5;create table testdb5.t05(name1 varchar(40),name2 varchar(40),name3 varchar(40));insert into testdb5.t05 values(@@hostname,@@hostname,@@hostname);create database testdb6;create table testdb6.t06(name1 varchar(40),name2 varchar(40),name3 varchar(40));insert into testdb6.t06 values(@@hostname,@@hostname,@@hostname);

node3

create database testdb7;create table testdb7.t07(name1 varchar(40),name2 varchar(40),name3 varchar(40));insert into testdb7.t07 values(@@hostname,@@hostname,@@hostname);create database testdb8;create table testdb8.t08(name1 varchar(40),name2 varchar(40),name3 varchar(40));insert into testdb8.t08 values(@@hostname,@@hostname,@@hostname);create database testdb9;create table testdb9.t09(name1 varchar(40),name2 varchar(40),name3 varchar(40));insert into testdb9.t09 values(@@hostname,@@hostname,@@hostname);

二、配置schema.xml

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

三、配置server.xml

                mysql                mycatdb1,mycatdb2,mycatdb3,mycatdb4,mycatdb5,mycatdb6,mycatdb7,mycatdb8,mycatdb9                                                        

四、启动mycat

/usr/local/mycat/bin/mycat start

查看mycat日志

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

五、访问8066端口查看数据

[root@mycat conf]# mysql -uroot -pmysql -P8066 -h292.168.8.30 -e "select * from mycatdb1.t01"mysql: [Warning] Using a password on the command line interface can be insecure.+-------+-------+-------+| name1 | name2 | name3 |+-------+-------+-------+| node1 | node1 | node1 |+-------+-------+-------+[root@mycat conf]# mysql -uroot -pmysql -P8066 -h292.168.8.30 -e "select * from mycatdb2.t02"mysql: [Warning] Using a password on the command line interface can be insecure.+-------+-------+-------+| name1 | name2 | name3 |+-------+-------+-------+| node1 | node1 | node1 |+-------+-------+-------+[root@mycat conf]# mysql -uroot -pmysql -P8066 -h292.168.8.30 -e "select * from mycatdb3.t03"mysql: [Warning] Using a password on the command line interface can be insecure.+-------+-------+-------+| name1 | name2 | name3 |+-------+-------+-------+| node1 | node1 | node1 |+-------+-------+-------+[root@mycat conf]# mysql -uroot -pmysql -P8066 -h292.168.8.30 -e "select * from mycatdb4.t04"mysql: [Warning] Using a password on the command line interface can be insecure.+-------+-------+-------+| name1 | name2 | name3 |+-------+-------+-------+| node2 | node2 | node2 |+-------+-------+-------+[root@mycat conf]# mysql -uroot -pmysql -P8066 -h292.168.8.30 -e "select * from mycatdb5.t05"mysql: [Warning] Using a password on the command line interface can be insecure.+-------+-------+-------+| name1 | name2 | name3 |+-------+-------+-------+| node2 | node2 | node2 |+-------+-------+-------+[root@mycat conf]# mysql -uroot -pmysql -P8066 -h292.168.8.30 -e "select * from mycatdb6.t06"mysql: [Warning] Using a password on the command line interface can be insecure.+-------+-------+-------+| name1 | name2 | name3 |+-------+-------+-------+| node2 | node2 | node2 |+-------+-------+-------+[root@mycat conf]# mysql -uroot -pmysql -P8066 -h292.168.8.30 -e "select * from mycatdb7.t07"mysql: [Warning] Using a password on the command line interface can be insecure.+-------+-------+-------+| name1 | name2 | name3 |+-------+-------+-------+| node3 | node3 | node3 |+-------+-------+-------+[root@mycat conf]# mysql -uroot -pmysql -P8066 -h292.168.8.30 -e "select * from mycatdb8.t08"mysql: [Warning] Using a password on the command line interface can be insecure.+-------+-------+-------+| name1 | name2 | name3 |+-------+-------+-------+| node3 | node3 | node3 |+-------+-------+-------+[root@mycat conf]# mysql -uroot -pmysql -P8066 -h292.168.8.30 -e "select * from mycatdb9.t09"mysql: [Warning] Using a password on the command line interface can be insecure.+-------+-------+-------+| name1 | name2 | name3 |+-------+-------+-------+| node3 | node3 | node3 |+-------+-------+-------+

数据查看正常,9个库分布在三个机器。



0