1、环境及版本

操作系统:   CentOS 7.5

MySQL:5.7.23

jdk:1.8.0_191

MyCat:1.6.6.1

cat /etc/centos-release
mysql -V
java -version

  

2、安装包准备

下载网站:http://dl.mycat.io/1.6.6/

【2】上传至linux服务器:

mkdir /home/rhr/soft/mycat
cd /home/rhr/soft/mycat
rz

  

3、开始安装

【1】解压

tar -zxvf Mycat-server-1.6-RELEASE-20161028204710-linux.tar.gz

【2】安装tree(可选,使目录结构更好看)

yum -y install tree

查看tree:

4、创建用户并修改配置文件

【1】为了更好的进入mycat,设置MYCAT_HOME的变量

vim /etc/profile

 添加绿色部分:


export JAVA_HOME=/home/rhr/soft/jdk/jdk1.8.0_191
export MYCAT_HOME=/home/rhr/soft/mycat/mycat
export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:/usr/local/mysql/bin:$MYCAT_HOME/bin:$PATH

使得变量生效
source /etc/profile

检查

【2】配置mycat文件

(1)修改server.xml

cd home/rhr/soft/mycat/mycat/conf
cp server.xml server_bak.xml
vim server.xml

修改前:

修改后:

(2)修改schema.xml

1)  修改schema 标签

修改前:

    <schema name="TESTDB" checkSQLschema="false" sqlMaxLimit="100">
<!-- auto sharding by id (long) -->
<table name="travelrecord" dataNode="dn1,dn2,dn3" rule="auto-sharding-long" /> <!-- global table is auto cloned to all defined data nodes ,so can join
with any table whose sharding node is in the same data node -->
<table name="company" primaryKey="ID" type="global" dataNode="dn1,dn2,dn3" />
<table name="goods" primaryKey="ID" type="global" dataNode="dn1,dn2" />
<!-- random sharding using mod sharind rule -->
<table name="hotnews" primaryKey="ID" autoIncrement="true" dataNode="dn1,dn2,dn3" rule="mod-long" />
<!-- <table name="dual" primaryKey="ID" dataNode="dnx,dnoracle2" type="global"
needAddLimit="false"/> <table name="worker" primaryKey="ID" dataNode="jdbc_dn1,jdbc_dn2,jdbc_dn3" rule="mod-long" /> -->
<table name="employee" primaryKey="ID" dataNode="dn1,dn2" rule="sharding-by-intfile" />
<table name="customer" primaryKey="ID" dataNode="dn1,dn2" rule="sharding-by-intfile">
<childTable name="orders" primaryKey="ID" joinKey="customer_id" parentKey="id">
<childTable name="order_items" joinKey="order_id" parentKey="id" />
</childTable>
<childTable name="customer_addr" primaryKey="ID" joinKey="customer_id" parentKey="id" />
</table>
<!-- <table name="oc_call" primaryKey="ID" dataNode="dn1$0-743" rule="latest-month-calldate" /> -->
</schema>

修改后:

    <schema name="TESTDB" checkSQLschema="false" sqlMaxLimit="100">
<!-- auto sharding by id (long) -->
<table name="travelrecord" dataNode="dn1,dn2,dn3" rule="auto-sharding-long" /> <!-- global table is auto cloned to all defined data nodes ,so can join
with any table whose sharding node is in the same data node --> <table name="company" primaryKey="company_id" type="global" dataNode="dn1,dn2,dn3" />
<table name="goods" primaryKey="goods_id" type="global" dataNode="dn1,dn2" /> <!-- random sharding using mod sharind rule -->
<table name="hotnews" primaryKey="hotnews_id" autoIncrement="true" dataNode="dn1,dn2,dn3" rule="mod-long" /> <!-- <table name="dual" primaryKey="ID" dataNode="dnx,dnoracle2" type="global"
needAddLimit="false"/> <table name="worker" primaryKey="ID" dataNode="jdbc_dn1,jdbc_dn2,jdbc_dn3" rule="mod-long" /> --> <table name="employee" primaryKey="employee_id" dataNode="dn1,dn2" rule="sharding-by-intfile" /> <table name="customer" primaryKey="customer_id" dataNode="dn1,dn2" rule="sharding-by-murmur">
<childTable name="orders" primaryKey="order_id" joinKey="customer_id" parentKey="customer_id">
<childTable name="order_items" joinKey="order_id" parentKey="order_id" />
</childTable>
<childTable name="customer_addr" primaryKey="customer_addr_id" joinKey="customer_id" parentKey="customer_id" />
</table>
<!-- <table name="oc_call" primaryKey="ID" dataNode="dn1$0-743" rule="latest-month-calldate" /> -->
</schema>

2)  修改schema 标签

修改前

        <!-- can have multi write hosts -->
<writeHost host="hostM1" url="localhost:3306" user="root" password="123">
<!-- can have multi read hosts -->
<readHost host="hostS2" url="localhost:3306" user="root" password="123" />
</writeHost>
<writeHost host="hostS1" url="localhost:3306" user="root" password="123" />
<!-- <writeHost host="hostM2" url="localhost:3316" user="root" password="123456"/> -->

修改后:

    <!-- can have multi write hosts -->
<writeHost host="hostM1" url="localhost:3306" user="root" password="YYBrhr_2018">
<!-- can have multi read hosts -->
<!-- <readHost host="hostS2" url="localhost:3306" user="root" password="123" /> -->
</writeHost>
<!-- <writeHost host="hostS1" url="localhost:3306" user="root" password="123" /> -->
<!-- <writeHost host="hostM2" url="localhost:3316" user="root" password="123456"/> -->
</dataHost>

(3)修改role.xml

修改前:

<tableRule name="sharding-by-intfile">
<rule>
<columns>sharding_id</columns>
<algorithm>hash-int</algorithm>
</rule>
</tableRule>
<tableRule name="auto-sharding-long">
<rule>
<columns>id</columns>
<algorithm>rang-long</algorithm>
</rule>
</tableRule>
<tableRule name="mod-long">
<rule>
<columns>id</columns>
<algorithm>mod-long</algorithm>
</rule>
</tableRule>
<tableRule name="sharding-by-murmur">
<rule>
<columns>id</columns>
<algorithm>murmur</algorithm>
</rule>
</tableRule>

修改后:

    <tableRule name="sharding-by-intfile">
<rule>
<columns>employee_id</columns>
<algorithm>hash-int</algorithm>
</rule>
</tableRule>
<tableRule name="auto-sharding-long">
<rule>
<columns>id</columns>
<algorithm>rang-long</algorithm>
</rule>
</tableRule>
<tableRule name="mod-long">
<rule>
<columns>hotnews_id</columns>
<algorithm>mod-long</algorithm>
</rule>
</tableRule>
<tableRule name="sharding-by-murmur">
<rule>
<columns>customer_id</columns>
<algorithm>murmur</algorithm>
</rule>
</tableRule>

5、启动mycat并测试

【1】启动mycat

mycat start
mycat status

【2】测试

mysql -u root -p -P8066 -h 127.0.0.1

这里输入的密码,是在/home/rhr/soft/mycat/mycat/conf/server.xml里面看到的密码

这样就说明安装成功了,安装或者启动mycat之前

最新文章

  1. Android开发3:Intent、Bundle的使用和ListView的应用 、RelativeLayout(相对布局)简述(简单通讯录的实现)
  2. android基础(六)android的消息处理机制
  3. Frame动画实战
  4. IE如何兼容placeholder属性
  5. 盘点 OSX 上最佳的 DevOps 工具
  6. 【转】cocos2d-x 2.0版本 自适应屏幕分辨率
  7. 【Android 复习】:Android五种布局的使用方法
  8. GridView and DropDownList
  9. x位全排列(next_permutation)
  10. day 7-19 Mysql索引原理与查询优化
  11. Atitit 3种类型的公司:运营驱动型;产品驱动型; 技术驱动型。
  12. BZOJ3417[Poi2013]Tales of seafaring——BFS
  13. Redis Nosql数据库
  14. haproxy 让后端服务器记录用户的真是IP地址(记录在header头里)
  15. 科学计算三维可视化---TraitsUI的介绍
  16. CAS 5.1.x 的搭建和使用(三)—— 通过官方示例来熟悉客户端搭建
  17. functools.wraps 带参数的装饰器 多个装饰器装饰同一个函数
  18. Spark应用程序运行的日志存在哪里(转)
  19. VS2012利用Wix打包问题
  20. HDU 2163 Palindromes

热门文章

  1. ACM学习历程—HDU 4287 Intelligent IME(字典树 || map)
  2. 物化视图基础概念、mview跨库迁移表
  3. NOI.AC 31 MST——整数划分相关的图论(生成树、哈希)
  4. Day09: socket网络编程-OSI七层协议,tcp/udp套接字,tcp粘包问题,socketserver
  5. Redis 教程笔记
  6. java.lang.NoClassDefFoundError: javassist/util/proxy/MethodFilter
  7. AngularJs(Part 1)
  8. Process打开文件
  9. 爬虫之BeautifulSoup, CSS
  10. Elasticsearch之match_phrase小坑记录