Mycat安装
本文以 Linux 系统为例,并假设您已安装好 java jdk
,如未安装,请自行查询安装教程。
下载安装包
1 | wget http://dl.mycat.org.cn/1.6.7.4/Mycat-server-1.6.7.4-release/Mycat-server-1.6.7.4-release-20200105164103-linux.tar.gz |
解压
1 | tar -zxvf Mycat-server-1.6.7.4-release-20200105164103-linux.tar.gz |
解压后进入 mycat
文件夹,主要了解下如下三个文件夹:
bin
启动程序目录conf
配置文件目录logs
日志目录
conf目录
以下是一些配置文件的配置参考,简化了部分配置,请参考该配置方式修改原配置文件
server.xml
设置逻辑数据库的账号密码、监听端口、解析方式1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29<?xml version="1.0" encoding="UTF-8"?>
<!-- - - Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License. - You
may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0
- - Unless required by applicable law or agreed to in writing, software -
distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the
License for the specific language governing permissions and - limitations
under the License. -->
<!DOCTYPE mycat:server SYSTEM "server.dtd">
<mycat:server xmlns:mycat="http://io.mycat/">
<system>
<!-- defaultSqlParser:指定默认的解析器(如解析sql),目前的可用的取值有:druidparser和 fdbparser。
使用的时候可以选择其中的一种,目前一般都使用druidparser -->
<property name="defaultSqlParser">druidparser</property>
<!-- 0:开启小数量级(默认) ;1:开启亿级数据排序-->
<property name="mutiNodeLimitType">1</property>
<property name="serverPort">8066</property>
<property name="managerPort">9066</property>
</system>
<!-- mycat 的用户名,密码,数据库 -->
<user name="root" defaultAccount="true">
<property name="password">123456</property>
<property name="schemas">testdb</property>
<property name="defaultSchema">testdb</property>
<!--No MyCAT Database selected 错误前会尝试使用该schema作为schema,不设置则为null,报错 -->
</user>
</mycat:server>schema.xml
用来配置真实数据库的一些配置 与逻辑数据库(虚拟数据库)的映射关系1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25<?xml version="1.0"?>
<!DOCTYPE mycat:schema SYSTEM "schema.dtd">
<mycat:schema xmlns:mycat="http://io.mycat/">
<schema name="testdb" checkSQLschema="false" dataNode="dn1">
<!-- auto sharding by id (long) -->
<!--splitTableNames 启用<table name 属性使用逗号分割配置多个表,即多个表使用这个配置-->
<table name="user" primaryKey="id" dataNode="dn1,dn2,dn3"/>
<table name="title" primaryKey="id" dataNode="dn1,dn2,dn3,dn4,dn5,dn6" autoIncrement="true" rule="auto-sharding-long"/>
</schema>
<dataNode name="dn1" dataHost="localhost1" database="db1" />
<dataNode name="dn2" dataHost="localhost1" database="db2" />
<dataNode name="dn3" dataHost="localhost1" database="db3" />
<dataNode name="dn4" dataHost="localhost1" database="db4" />
<dataNode name="dn5" dataHost="localhost1" database="db5" />
<dataNode name="dn6" dataHost="localhost1" database="db6" />
<dataHost name="localhost1" maxCon="1000" minCon="10" balance="0" writeType="0" dbType="mysql" dbDriver="native" switchType="1" slaveThreshold="100">
<heartbeat>select user()</heartbeat>
<!-- can have multi write hosts -->
<writeHost host="hostM1" url="localhost:3306" user="root"
password="123456">
</writeHost>
</dataHost>
</mycat:schema>
启动
1 | ./bin/mycat start |
命令列表:
- console 前台启动
- start 后台启动
- stop 停止
- restart 重启
- status 查看状态
测试
1 | # mysql -uroot -p123456 -h127.0.0.1 -P8066 |