1、去Mycat官网下载linux版mycat压缩包,下载地址
http://www.mycat.io/
下载完成后上传至linux
2、解压
tar -zxvf Mycat-server-1.6.6.1-release-20181031195535-linux.tar.gz
3、 配置环境变量
vi /etc/profile
在文件末尾添加如下配置:
export MYCAT_HOME=/home/softs/mycat
export PATH=$JAVAHOME/bin:$MYCATHOME/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
使文件立即生效
source /etc/profile
4、查看配置是否生效:
mycat --version
如果出现如下提示表示已生效
Usage: /home/softs/mycat/bin/mycat { console | start | stop | restart | status | dump }
5、修改schema.xml配置
vi mycat/conf/schema.xml
配置如下,相关参数说明请参考《Mycat读写分离与按月分片》
<schema name="dream_db" checkSQLschema="false" sqlMaxLimit="100">
<table name="hello" primaryKey="id" dataNode="dn$1-12" rule="sharding-by-month" />
</schema>
<dataNode name="dn$1-12" dataHost="localhost1" database="db$1-12" />
<dataHost name="localhost1" maxCon="1000" minCon="10" balance="3"
writeType="0" dbType="mysql" dbDriver="native" switchType="-1" slaveThreshold="100">
<heartbeat>show slave status</heartbeat>
<writeHost host="hostM1" url="localhost:3316" user="root"
password="root">
<readHost host="hostS1" url="localhost:3317" user="root" password="root" />
</writeHost>
</dataHost>
</mycat:schema>
6、修改rule.xml分片规则配置文件
<tableRule name="sharding-by-month">
<rule>
<columns>rpt_time</columns>
<algorithm>partbymonth</algorithm>
</rule>
</tableRule>
<function name="partbymonth"
class="io.mycat.route.function.PartitionByMonth">
<property name="dateFormat">yyyy-MM-dd</property>
<!--<property name="sBeginDate">2015-01-01</property>-->
</function>
6、修改server.xml配置文件设置Mycat用户名、密码和逻辑库
<user name="root" defaultAccount="true">
<property name="password">123456</property>
<property name="schemas">dream_db</property>
</user>
<user name="user">
<property name="password">user</property>
<property name="schemas">dream_db</property>
<property name="readOnly">true</property>
</user>
7、启动Mycat
cd mycat/bin/
mycat start
8、登录mycat
mysql -uroot -p123456 -P8066 -h192.168.120.135
切换数据库dream_db
use dream_db
即可操作数据库