mycat简单配置及简单使用

2 篇文章 0 订阅

我的环境:
使用了两个机器:
rws1270149
rws1270173
两个机器上都是在3306端口上跑着一个mysql实例

在两个mysql实例上都创建u123这个用户并赋予权限

mycat的参数文件server.xml 里面配置的user其实是在mysql里面创建的

mysql> create user 'u123'@'%' identified by 'u123';
Query OK, 0 rows affected (0.00 sec)

mysql> grant all on *.* to 'u123'@'%';
Query OK, 0 rows affected (0.00 sec)

[crsusr@rws1270149 conf]$ mysql -uu123 -pu123 -P8066 -DTESTDB
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 1049 (42000): Unknown database 'TESTDB'
报错说TESTDB这个逻辑库unknown,其实原因是因为没有加-h参数
[crsusr@rws1270149 conf]$ mysql -uu123 -pu123 -P8066 -DTESTDB -h127.0.0.1
mysql: [Warning] Using a password on the command line interface can be insecure.
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

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

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

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

mysql>

server.xml文件的配置

TESTDB这个逻辑库是在schema.xml文件里配置的

        <user name="u123">
                <property name="password">u123</property>
                <property name="schemas">TESTDB</property>
                <property name="readOnly">false</property>
        </user>

schema.xml需要配置四个部分

dataHost dataNode schema table

dataHost部分配置,不知道这里配置的user和password什么时候用

<dataHost name="dh149" maxCon="100" minCon="10" balance="3"
                          writeType="0" dbType="mysql" dbDriver="native" switchType="1"  slaveThreshold="100">
                <heartbeat>select user()</heartbeat>
                <writeHost host="hostM1" url="rws1270149:3306" user="root"
                                   password="pass">
                </writeHost>
        </dataHost>
        <dataHost name="dh173" maxCon="100" minCon="10" balance="3"
                          writeType="0" dbType="mysql" dbDriver="native" switchType="1"  slaveThreshold="100">
                <heartbeat>select user()</heartbeat>
                <writeHost host="hostM1" url="rws1270173:3306" user="root"
                                   password="pass">
                </writeHost>
        </dataHost>

相应的db1 db2 db3 db4需要在两个机器上的mysql实例上创建

<dataNode name="dn1" dataHost="dh149" database="db1" />
        <dataNode name="dn2" dataHost="dh149" database="db2" />
        <dataNode name="dn3" dataHost="dh173" database="db3" />
        <dataNode name="dn4" dataHost="dh173" database="db4" />

schema和table的配置
TESTDB这个逻辑库是在server.xml里面需要的

<schema name="TESTDB" checkSQLschema="false" sqlMaxLimit="100">
                <!-- auto sharding by id (long) -->
                <table name="travelrecord" dataNode="dn1,dn2,dn3,dn4" rule="auto-sharding-long" />

        </schema>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值