使用MyCAT代理MySQL数据库

环境中需要使用统一入口访问多数据库,环境下有B2C、B2B、O2O数据库,现针对所有B2C、B2B、O2O中的所有订单进行聚合搭建一个类似京东京享值一样的会员级别系统,针对不同级别会员给予不同的优惠。

数据库 数据库主机 数据库用户名 数据库用密码 备注
b2c 192.168.0.200 root 123456 B2C数据库
b2b 192.168.0.201 root 123456 B2B数据库
o2o 192.168.0.202 root 123456 O2O数据库

1.先安装JDK
tar zxf jdk-8u211-linux-x64.tar.gz
mv jdk1.8.0_211 /usr/local/

2.配置PATH
echo 'export PATH=/usr/local/jdk1.8.0_211/bin:$PATH'>>/etc/profile
source /etc/profile
java -version

3.下载mycat
wget http://dl.mycat.io/1.6.6.1/Mycat-server-1.6.6.1-release-20181031195535-linux.tar.gz
mv mycat /usr/local/

4.配置mycat
配置server.xml
cd /usr/local/mycat
cp -rf conf conf_ori
cd conf
vim server.xml

 


        
        0
        1
        0
        0
                2
        false
                0
                0
                1
        64k
                1k
                0
                384m
                false
                false
                true
        
        
                123456
                b2c,b2b,o2o
        

        
                user
                b2c,b2b,o2o
                false
        


vim schema.xml




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

可以看到关键的逻辑是这个schema.xml配置文件

5.启动mycat并查看日志
启动mycat
/usr/local/mycat/bin/mycat start
查看日志
vim /usr/local/mycat/logs/wrapper.log
显示

STATUS | wrapper  | 2019/05/26 18:28:10 | --> Wrapper Started as Daemon
STATUS | wrapper  | 2019/05/26 18:28:10 | Launching a JVM...
INFO   | jvm 1    | 2019/05/26 18:28:10 | Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=64M; support was removed in 8.0
INFO   | jvm 1    | 2019/05/26 18:28:11 | Wrapper (Version 3.2.3) http://wrapper.tanukisoftware.org
INFO   | jvm 1    | 2019/05/26 18:28:11 |   Copyright 1999-2006 Tanuki Software, Inc.  All Rights Reserved.
INFO   | jvm 1    | 2019/05/26 18:28:11 |
INFO   | jvm 1    | 2019/05/26 18:28:12 | MyCAT Server startup successfully. see logs in logs/mycat.log

可以看到服务启动了

6.查看结果
mysql -h127.0.0.1 -P8066 -uroot -p123456

Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.29-mycat-1.6.6.1-release-20181031195535 MyCat Server (OpenCloudDB)

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MySQL [(none)]> show databases;
+----------+
| DATABASE |
+----------+
| b2b      |
| o2o      |
| b2c    |
+----------+
3 rows in set (0.00 sec)

转载于:https://blog.51cto.com/fengwan/2400360

你可能感兴趣的:(数据库,前端,开发工具)