环境
下载
Windows 使用
Windows (mycat)
Linux 虚拟机(主库)
Linux 虚拟机(从裤)
注:主从同步需要自己配置,参考 有道:
mysql主从同步配置.note ,Blog:
MySQL 主从同步配置
百度网盘下载
整个git仓库下载(2016-07-06,链接:
http://pan.baidu.com/s/1o86bSbo 密码:ad4a)
Windows 环境下载(
http://pan.baidu.com/s/1miRKZpe)
1. 解压Windows包
2. 配置
修改conf下的
server.xml(配置mycat用户名)
1
2
3
4
5
6
7
8
9
10
11
12
|
<
system
>
<
property
name
=
"defaultSqlParser"
>druidparser</
property
>
</
system
>
<
user
name
=
"mycat"
>
<
property
name
=
"password"
>mycat</
property
>
<
property
name
=
"schemas"
>test_schema</
property
>
</
user
>
</
mycat:server
>
|
修改conf下的
schema.xml(配置读写分离)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
<
schema
name
=
"test_schema"
checkSQLschema
=
"false"
sqlMaxLimit
=
"100"
dataNode
=
"dn1"
></
schema
>
<
dataNode
name
=
"dn1"
dataHost
=
"testhost"
database
=
"test_mycat"
/>
<
dataHost
name
=
"testhost"
maxCon
=
"1000"
minCon
=
"10"
balance
=
"1"
dbType
=
"mysql"
dbDriver
=
"native"
slaveThreshold
=
"100"
>
<
heartbeat
>select user()</
heartbeat
>
<!-- can have multi write hosts -->
<
writeHost
host
=
"hostM1"
url
=
"192.168.17.135:3306"
user
=
"root"
password
=
"root"
>
<!-- can have multi read hosts -->
<
readHost
host
=
"hostS2"
url
=
"192.168.17.134:3306"
user
=
"root"
password
=
"root"
/>
</
writeHost
>
</
dataHost
>
</
mycat:schema
>
|
参数说明:
balance 属性(负载均衡类型)
balance="0", 不开启读写分离机制,所以读操作都发送到当前可用的writeHost上。
balance="1",全部的readHost与stand by writeHost 参与select语句的负载均衡,简单的说,当双主双从模式(M1->S1,M2->S2,并且M1和M2互为主备),正常情况下,M2,S1,S2 都参 select语句的负载均衡。
balance="2",所有读操作都随机的在 writeHost、 readhost 上分发。
balance="3",所有读请求随机分发到 wiriterHost 对应的 readhost 执行,writerHost不负担读压力。
其他参数详情参考官方文档6.6.1章节
3. 运行
Windows:
直接运行startup_nowrap.bat(有报错可以查看log目录下的日志)
4. 测试验证
使用navicat连接mycat,端口为
8066,用户名密码为server.xml所配置的。
执行写操作:
insert into test values('jerome2',2);(可在主库的mysql log看到插入一条数据,从库日志可看到同步了这条数据)
执行读操作:
SELECT * FROM test; (可在从库看到查询日志,主库没有日志)