我的环境:
使用了两个机器:
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>