mycat拆分实例

背景:
mycat1:172.16.4.0
mycat2:172.16.4.1
mycat3:172.16.4.2
mycat-machine:172.16.4.3

4台虚拟机上都安装mysql,
mycat-machine上安装mycat,

搭建步骤:
mycat-machine上的操作:
1、安装mycat

 rpm -ivh jdk-8u111-linux-x64.rpm
 tar xf Mycat-server-1.6-RELEASE-20161028204710-linux.tar.gz -C /usr/local/
 
 

2、修改PATH变量

[root@mycat-machine ~]# vi /etc/profile

在这里插入图片描述
3、修改环境变量,将mycat命令的路径加进去

[root@mycat-machine ~]# vi /root/.bash_profile 

mycat拆分实例_第1张图片
4、启动调试mycat

目的是看mycat是否配置好,不报错就ctrl C退出

[root@mycat-machine ~]# mycat console
[root@mycat-machine ~]# mycat start

5、配置mycat的垂直拆分

  • 1、编辑配置文件server.xml
  cd   /usr/local/mycat/conf

可以使用用户root,密码123456,主机127.0.0.1,8066数据端口后期进行登录数据库
mycat拆分实例_第2张图片

  • 2、 编辑schema.xml文件
    mycat拆分实例_第3张图片根据rule规则修改rule.xml文件
    mycat拆分实例_第4张图片
    根据规则对应的算法找到对应函数
    mycat拆分实例_第5张图片
    然后打开txt文件修改规则
    mycat拆分实例_第6张图片

  • 3、根据自己配置的内容,去相应节点上建立数据库和表
    172.16.4.0上
    建立db1和db2数据库
    db1库中创建orders_info表
    db2库中创建goods_info表
    172.16.4.1上
    建立db3和db4数据库
    db3库中创建orders_info表
    db4库中创建goods_info表
    172.16.4.2上
    建立db5和db6数据库
    db5库中创建orders_info、goods_info表
    db6库中创建goods_info表

  • 4、在后端数据库给mycat机器建立用户
    172.16.4.0上

grant all on db1.* to 'root'@'172.16.4.3' identified by 123';
grant all on db2.* to 'root'@'172.16.4.3' identified by '123';

172.16.4.1上

grant all on db3.* to 'root'@'172.16.4.3' identified by 123';
grant all on db4.* to 'root'@'172.16.4.3' identified by '123';

172.16.4.2上

grant all on db5.* to 'root'@'172.16.4.3' identified by 123';
grant all on db6.* to 'root'@'172.16.4.3' identified by '123';
  • 5、 启动mycat,看是否有报错mycat console 、 mycat start
  • 6、9066管理端口登录
    mycat拆分实例_第7张图片mycat拆分实例_第8张图片
  • 7、8066数据端口登录,验证拆分
[root@mycat-machine ~]# mysql -uroot -p123456 -h127.0.0.1 -P8066
mysql> show databases;
+----------+
| DATABASE |
+----------+
| SHOP     |
+----------+
1 row in set (0.00 sec)

mysql> use SHOP;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> select * from orders_info for update;
+-----------+-----------+---------+---------------------+---------------------+-------------+
| orders_id | status_id | user_id | order_time          | order_pay_time      | order_money |
+-----------+-----------+---------+---------------------+---------------------+-------------+
|     50001 |         1 |       1 | 2018-02-03 12:00:00 | 2018-02-03 12:00:01 |        2390 |
|     50002 |         1 |       1 | 2018-02-03 12:00:00 | 2018-02-03 12:00:01 |        2390 |
|    100000 |         1 |       1 | 2018-02-03 12:00:00 | 2018-02-03 12:00:01 |        2390 |
|         1 |         1 |       1 | 2018-02-03 12:00:00 | 2018-02-03 12:00:01 |        2390 |
|       101 |         1 |       2 | 2018-02-03 12:00:00 | 2018-02-03 12:00:01 |        2390 |
|       500 |         1 |       1 | 2018-07-19 16:58:42 | 2018-02-03 16:58:42 |       23293 |
|       501 |         1 |       1 | 2018-02-03 12:00:00 | 2018-02-03 12:00:01 |        2390 |
|      4999 |         1 |       1 | 2018-06-02 16:04:32 | 2018-02-03 16:04:32 |        2323 |
|      5019 |         1 |       1 | 2018-07-19 17:09:19 | 2018-02-03 17:09:19 |        2323 |
|    150001 |         1 |       1 | 2018-02-03 12:00:00 | 2018-02-03 12:00:01 |        2390 |
|    100001 |         1 |       1 | 2018-02-03 12:00:00 | 2018-02-03 12:00:01 |        2390 |
|    100202 |         1 |       2 | 2018-02-03 12:00:00 | 2018-02-03 12:00:01 |        2390 |
+-----------+-----------+---------+---------------------+---------------------+-------------+
12 rows in set (0.17 sec)

mysql> explain select * from orders_info where orders_id=50001;
+-----------+-------------------------------------------------+
| DATA_NODE | SQL                                             |
+-----------+-------------------------------------------------+
| dn2       | select * from orders_info where orders_id=50001 |
+-----------+-------------------------------------------------+
1 row in set (0.00 sec)

mysql> 

你可能感兴趣的:(mysql,mycat拆分实例)