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=$JAVA_HOME/bin:$MYCAT_HOME/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
复制
即可操作数据库
文章转载自码农小黑,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。