当前位置:   article > 正文

mycat注解命令行学习小记_mycat 注解

mycat 注解
  1. #创建数据源
  2. #创建dbw写库,指向集群中的master服务
  3. /*+ mycat:createDataSource{"name":"dbW","url":"jdbc:mysql://172.17.0.5:3306/mysql?useSSL=false&characterEncoding=UTF-8&useJDBCCompliantTimezoneShift=true","user":"root","password":"123456"} */;
  4. #创建dbR读库,指向集群中的slave服务。如果有多个从库,依次继续创建
  5. /*+ mycat:createDataSource{"name":"dbR","url":"jdbc:mysql://172.17.0.6:3306/mysql?useSSL=false&characterEncoding=UTF-8&useJDBCCompliantTimezoneShift=true","user":"root","password":"123456"} */;
  6. #查询配置数据库结果
  7. /*+ mycat:showDataSources{} */;
  1. #更新集群信息
  2. /*! mycat:createCluster{"name":"WRSplitCluster","masters":["dbW"],"replicas":["dbR"]} */;
  3. #查看配置集群信息
  4. /*+ mycat:showClusters{} */;
  1. #1、在mycat2的服务中声明一个逻辑库
  2. create database wrdb;
  3. #2、在mycat2的部署目录下,找到对应的配置文件,conf/schema/wrdb.schema.json。在其中增加targetName:WRSplitCluster属性。指向真实的集群。{"customTables":{},"globalTables":{},"normalProcedures":{},"normalTables":{},schemaName":"wrdb","targetName":"WRSplitCluster","shardingTables":{},"views":{}}
  4. #3、手动修改配置文件之后,需要重启MyCat2服务,让配置文件生效。
  1. #单表创建语句(其他表更换建表语句)
  2. /*+ mycat:createTable{
  3. "normalTable":{
  4. "createTableSQL":"CREATE TABLE `migrations` (
  5. `version` varchar(255) NOT NULL,
  6. PRIMARY KEY (`version`)
  7. ) ENGINE=InnoDB DEFAULT CHARSET=utf8",
  8. "locality":{
  9. "schemaName":"wrdb", //物理库
  10. "tableName":"migrations", //物理表
  11. "targetName":"WRSplitCluster" //集群,单表默认在prototype
  12. }
  13. },
  14. "schemaName":"wrdb",//逻辑库
  15. "tableName":"migrations" //逻辑表
  16. } */;
  1. #指定数据库分片表(其他表更换建表语句)
  2. /*+ mycat:createTable{
  3. "schemaName":"wrdb",
  4. "shardingTable":{
  5. "createTableSQL":"CREATE TABLE `travelrecord` (
  6. `id` bigint NOT NULL AUTO_INCREMENT,
  7. `user_id` varchar(100) DEFAULT NULL,
  8. `traveldate` date DEFAULT NULL,
  9. `fee` decimal(10,0) DEFAULT NULL,
  10. `days` int DEFAULT NULL,
  11. `blob` longblob,
  12. PRIMARY KEY (`id`),
  13. KEY `id` (`id`)
  14. ) ENGINE=InnoDB DEFAULT CHARSET=utf8 DBPARTITION BY MOD_HASH(id) DBPARTITIONS 1 TBPARTITION BY MOD_HASH(id) TBPARTITIONS 4",
  15. "function":{
  16. "properties":{
  17. "dbNum":1,
  18. "mappingFormat":"WRSplitCluster/wrdb/travelrecord_${index}",
  19. "tableNum":4,
  20. "tableMethod":"mod_hash(id)",
  21. "storeNum":1,
  22. "dbMethod":"mod_hash(id)"
  23. }
  24. },
  25. "partition":{
  26. }
  27. },
  28. "tableName":"travelrecord"
  29. } */;
  1. 分片表(其他表更换建表语句)
  2. /*+ mycat:createTable{
  3. "schemaName":"my_db",
  4. "shardingTable":{
  5. "createTableSQL":"CREATE TABLE `travelrecord` (
  6. `id` bigint NOT NULL AUTO_INCREMENT,
  7. `user_id` varchar(100) DEFAULT NULL,
  8. `traveldate` date DEFAULT NULL,
  9. `fee` decimal(10,0) DEFAULT NULL,
  10. `days` int DEFAULT NULL,
  11. `blob` longblob,
  12. PRIMARY KEY (`id`),
  13. KEY `id` (`id`)
  14. ) ENGINE=InnoDB DEFAULT CHARSET=utf8 DBPARTITION BY MOD_HASH(id) DBPARTITIONS 1 TBPARTITION BY MOD_HASH(id) TBPARTITIONS 4",
  15. "function":{
  16. "properties":{
  17. "dbNum":1,
  18. "mappingFormat":"c${targetIndex}/my_db_${dbIndex}/travelrecord_${index}",
  19. "tableNum":4,
  20. "tableMethod":"mod_hash(id)",
  21. "storeNum":1,
  22. "dbMethod":"mod_hash(id)"
  23. }
  24. },
  25. "partition":{
  26. }
  27. },
  28. "tableName":"travelrecord"
  29. } */;

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/凡人多烦事01/article/detail/407297
推荐阅读
相关标签
  

闽ICP备14008679号