github.com/XiaoMi/Gaea@v1.2.5/docs/shard-example.md (about) 1 # gaea 分片规则示例说明 2 3 ## 导航 4 - [gaea kingshard hash分片示例](#gaea_kingshard_hash) 5 - [gaea kingshard mod分片示例](#gaea_kingshard_mod) 6 - [gaea kingshard range分片示例](#gaea_kingshard_range) 7 - [gaea kingshard date year分片示例](#gaea_kingshard_date_year) 8 - [gaea kingshard date month分片示例](#gaea_kingshard_date_month) 9 - [gaea kingshard date day分片示例](#gaea_kingshard_date_day) 10 - [gaea mycat mod分片示例](#gaea_mycat_mod) 11 - [gaea mycat_long(固定hash分片算法)分片示例](#gaea_mycat_long) 12 - [gaea mycat_murmur(一致性Hash)分片示例](#gaea_mycat_partitionByMurmurHash) 13 - [gaea mycat_string(字符串拆分hash)分片示例](#gaea_mycat_partitionByString) 14 15 <h2 id="gaea_kingshard_hash">gaea kingshard hash分片示例</h2> 16 17 我们预定义两个slice slice-0、slice-1,每个slice定义一个库,每个库预定义2张表,其中slice-0的主库地址为127.0.0.1:3307,slice-1的主库地址为127.0.0.1:3308。 18 19 Gaea启动地址为127.0.0.1:13307 20 21 ### namespace配置 22 ```json 23 { 24 "name": "test_kingshard_hash", 25 "online": true, 26 "read_only": false, 27 "allowed_dbs": { 28 "db_kingshard": true 29 }, 30 "default_phy_dbs": { 31 "db_kingshard": "db_kingshard" 32 }, 33 "slow_sql_time": "1000", 34 "black_sql": [ 35 "" 36 ], 37 "allowed_ip": null, 38 "slices": [ 39 { 40 "name": "slice-0", 41 "user_name": "root", 42 "password": "1234", 43 "master": "127.0.0.1:3307", 44 "slaves": [], 45 "statistic_slaves": null, 46 "capacity": 12, 47 "max_capacity": 24, 48 "idle_timeout": 60 49 }, 50 { 51 "name": "slice-1", 52 "user_name": "root", 53 "password": "1234", 54 "master": "127.0.0.1:3308", 55 "slaves": [], 56 "statistic_slaves": [], 57 "capacity": 12, 58 "max_capacity": 24, 59 "idle_timeout": 60 60 } 61 ], 62 "shard_rules": [ 63 { 64 "db": "db_kingshard", 65 "table": "shard_hash", 66 "type": "hash", 67 "key": "id", 68 "locations": [ 69 2, 70 2 71 ], 72 "slices": [ 73 "slice-0", 74 "slice-1" 75 ] 76 } 77 ], 78 "users": [ 79 { 80 "user_name": "test", 81 "password": "1234", 82 "namespace": "test_kingshard_hash", 83 "rw_flag": 2, 84 "rw_split": 1, 85 "other_property": 0 86 } 87 ], 88 "default_slice": "slice-1", 89 "global_sequences": null 90 } 91 ``` 92 93 ### 创建数据库表 94 ```shell script 95 #连接3307数据库实例 96 mysql -h127.0.0.1 -P3307 -uroot -p1234 97 #创建数据库 98 create database db_kingshard; 99 #在命令行执行以下命令,创建分表shard_hash_0000、shard_hash_0001 100 for i in `seq 0 1`;do mysql -h127.0.0.1 -P3307 -uroot -p1234 db_kingshard -e "CREATE TABLE IF NOT EXISTS shard_hash_000"${i}" ( id INT(64) NOT NULL, col1 VARCHAR(256),PRIMARY KEY (id)) ENGINE=InnoDB DEFAULT CHARSET=utf8;";done 101 102 #连接3306数据库实例 103 mysql -h127.0.0.1 -P3308 -uroot -p1234 104 #创建数据库 105 create database db_kingshard; 106 #在命令行执行以下命令,创建分表shard_hash_0002、shard_hash_0003 107 for i in `seq 2 3`;do mysql -h127.0.0.1 -P3308 -uroot -p1234 db_kingshard -e "CREATE TABLE IF NOT EXISTS shard_hash_000"${i}" ( id INT(64) NOT NULL, col1 VARCHAR(256),PRIMARY KEY (id)) ENGINE=InnoDB DEFAULT CHARSET=utf8;";done 108 #登录3307示例,查询slice-0分片表展示: 109 mysql> show tables; 110 +------------------------+ 111 | Tables_in_db_kingshard | 112 +------------------------+ 113 | shard_hash_0000 | 114 | shard_hash_0001 | 115 +------------------------+ 116 2 rows in set (0.01 sec) 117 #登录3308示例,查询slice-1分片表展示: 118 mysql> show tables; 119 +------------------------+ 120 | Tables_in_db_kingshard | 121 +------------------------+ 122 | shard_hash_0002 | 123 | shard_hash_0003 | 124 +------------------------+ 125 2 rows in set (0.00 sec) 126 ``` 127 128 ### 插入数据 129 ```shell script 130 #命令行执行,该命令连接Gaea执行插入: 131 for i in `seq 1 10`;do mysql -h127.0.0.1 -P13306 -utest -p1234 db_kingshard -e "insert into shard_hash (id, col1) values(${i}, 'test$i')";done 132 ``` 133 134 ### 查看数据 135 ```shell script 136 #连接gaea,进行数据查询: 137 mysql> select * from shard_hash; 138 +----+--------+ 139 | id | col1 | 140 +----+--------+ 141 | 4 | test4 | 142 | 8 | test8 | 143 | 1 | test1 | 144 | 5 | test5 | 145 | 9 | test9 | 146 | 2 | test2 | 147 | 6 | test6 | 148 | 10 | test10 | 149 | 3 | test3 | 150 | 7 | test7 | 151 +----+--------+ 152 10 rows in set (0.03 sec) 153 #连接3307数据库实例,对slice-0分表数据进行查询: 154 mysql> select * from shard_hash_0000; 155 +----+-------+ 156 | id | col1 | 157 +----+-------+ 158 | 4 | test4 | 159 | 8 | test8 | 160 +----+-------+ 161 2 rows in set (0.00 sec) 162 mysql> select * from shard_hash_0001; 163 +----+-------+ 164 | id | col1 | 165 +----+-------+ 166 | 1 | test1 | 167 | 5 | test5 | 168 | 9 | test9 | 169 +----+-------+ 170 3 rows in set (0.01 sec) 171 #连接3308数据库实例,对slice-1分表数据进行查询: 172 mysql> select * from shard_hash_0002; 173 +----+--------+ 174 | id | col1 | 175 +----+--------+ 176 | 2 | test2 | 177 | 6 | test6 | 178 | 10 | test10 | 179 +----+--------+ 180 3 rows in set (0.01 sec) 181 mysql> select * from shard_hash_0003; 182 +----+-------+ 183 | id | col1 | 184 +----+-------+ 185 | 3 | test3 | 186 | 7 | test7 | 187 +----+-------+ 188 2 rows in set (0.01 sec) 189 ``` 190 191 <h2 id="gaea_kingshard_mod">gaea kingshard mod分片示例</h2> 192 193 我们预定义两个分片slice-0、slice-1,每个slice定义一个库,每个库预定义2张表,其中slice-0的主库地址为127.0.0.1:3307,slice-1的主库地址为127.0.0.1:3308。 194 195 Gaea启动地址为127.0.0.1:13307 196 197 ### namespace配置 198 ```json 199 { 200 "name": "test_kingshard_mod", 201 "online": true, 202 "read_only": false, 203 "allowed_dbs": { 204 "db_kingshard": true 205 }, 206 "default_phy_dbs": { 207 "db_kingshard": "db_kingshard" 208 }, 209 "slow_sql_time": "1000", 210 "black_sql": [ 211 "" 212 ], 213 "allowed_ip": null, 214 "slices": [ 215 { 216 "name": "slice-0", 217 "user_name": "root", 218 "password": "1234", 219 "master": "127.0.0.1:3307", 220 "slaves": [], 221 "statistic_slaves": null, 222 "capacity": 12, 223 "max_capacity": 24, 224 "idle_timeout": 60 225 }, 226 { 227 "name": "slice-1", 228 "user_name": "root", 229 "password": "1234", 230 "master": "127.0.0.1:3308", 231 "slaves": [], 232 "statistic_slaves": [], 233 "capacity": 12, 234 "max_capacity": 24, 235 "idle_timeout": 60 236 } 237 ], 238 "shard_rules": [ 239 { 240 "db": "db_kingshard", 241 "table": "shard_mod", 242 "type": "mod", 243 "key": "id", 244 "locations": [ 245 2, 246 2 247 ], 248 "slices": [ 249 "slice-0", 250 "slice-1" 251 ] 252 } 253 ], 254 "users": [ 255 { 256 "user_name": "test", 257 "password": "1234", 258 "namespace": "test_kingshard_mod", 259 "rw_flag": 2, 260 "rw_split": 1, 261 "other_property": 0 262 } 263 ], 264 "default_slice": "slice-1", 265 "global_sequences": null 266 } 267 ``` 268 269 ### 创建数据库表 270 ```shell script 271 #连接3307数据库实例 272 mysql -h127.0.0.1 -P3307 -uroot -p1234 273 #创建数据库 274 create database db_kingshard; 275 #在命令行执行以下命令,创建分表,shard_mod_0000、shard_mod_0001 276 for i in `seq 0 1`;do mysql -h127.0.0.1 -P3307 -uroot -p1234 db_kingshard -e "CREATE TABLE IF NOT EXISTS shard_mod_000"${i}" ( id INT(64) NOT NULL, col1 VARCHAR(256),PRIMARY KEY (id)) ENGINE=InnoDB DEFAULT CHARSET=utf8;";done 277 278 #连接3306数据库实例 279 mysql -h127.0.0.1 -P3308 -uroot -p1234 280 #创建数据库 281 create database db_kingshard; 282 #在命令行执行以下命令,创建分表,shard_mod_0002、shard_mod_0003 283 for i in `seq 2 3`;do mysql -h127.0.0.1 -P3308 -uroot -p1234 db_kingshard -e "CREATE TABLE IF NOT EXISTS shard_mod_000"${i}" ( id INT(64) NOT NULL, col1 VARCHAR(256),PRIMARY KEY (id)) ENGINE=InnoDB DEFAULT CHARSET=utf8;";done 284 #登录3307实例,查询slice-0分片表展示: 285 mysql> show tables; 286 +------------------------+ 287 | Tables_in_db_kingshard | 288 +------------------------+ 289 | shard_mod_0000 | 290 | shard_mod_0001 | 291 +------------------------+ 292 2 rows in set (0.01 sec) 293 #登录3308示例,查询slice-1分片表展示: 294 mysql> show tables; 295 +------------------------+ 296 | Tables_in_db_kingshard | 297 +------------------------+ 298 | shard_mod_0002 | 299 | shard_mod_0003 | 300 +------------------------+ 301 2 rows in set (0.00 sec) 302 ``` 303 304 ### 插入数据 305 ```shell script 306 #命令行执行,该命令连接Gaea执行插入: 307 for i in `seq 1 10`;do mysql -h127.0.0.1 -P13306 -utest -p1234 db_kingshard -e "insert into shard_mod (id, col1) values(${i}, 'test$i')";done 308 ``` 309 310 ### 查看数据 311 ```shell script 312 #连接gaea,进行数据查询: 313 mysql> select * from shard_mod; 314 +----+--------+ 315 | id | col1 | 316 +----+--------+ 317 | 4 | test4 | 318 | 8 | test8 | 319 | 1 | test1 | 320 | 5 | test5 | 321 | 9 | test9 | 322 | 2 | test2 | 323 | 6 | test6 | 324 | 10 | test10 | 325 | 3 | test3 | 326 | 7 | test7 | 327 +----+--------+ 328 10 rows in set (0.03 sec) 329 330 #连接3307数据库实例,对slice-0分表数据进行查询: 331 mysql> select * from shard_mod_0000; 332 +----+-------+ 333 | id | col1 | 334 +----+-------+ 335 | 4 | test4 | 336 | 8 | test8 | 337 +----+-------+ 338 2 rows in set (0.00 sec) 339 mysql> select * from shard_mod_0001; 340 +----+-------+ 341 | id | col1 | 342 +----+-------+ 343 | 1 | test1 | 344 | 5 | test5 | 345 | 9 | test9 | 346 +----+-------+ 347 3 rows in set (0.01 sec) 348 349 #连接3308数据库实例,对slice-1分表数据进行查询: 350 mysql> select * from shard_mod_0002; 351 +----+--------+ 352 | id | col1 | 353 +----+--------+ 354 | 2 | test2 | 355 | 6 | test6 | 356 | 10 | test10 | 357 +----+--------+ 358 3 rows in set (0.00 sec) 359 mysql> select * from shard_mod_0003; 360 +----+-------+ 361 | id | col1 | 362 +----+-------+ 363 | 3 | test3 | 364 | 7 | test7 | 365 +----+-------+ 366 2 rows in set (0.01 sec) 367 ``` 368 369 <h2 id="gaea_kingshard_range">gaea kingshard range分片示例</h2> 370 371 我们预定义两个slice slice-0、slice-1,每个slice定义一个库,每个库预定义2张表,其中slice-0的主库地址为127.0.0.1:3307,slice-1的主库地址为127.0.0.1:3308。 372 373 Gaea启动地址为127.0.0.1:13307 374 375 ### namespace配置 376 ```json 377 { 378 "name": "test_kingshard_range", 379 "online": true, 380 "read_only": false, 381 "allowed_dbs": { 382 "db_kingshard": true 383 }, 384 "default_phy_dbs": { 385 "db_kingshard": "db_kingshard" 386 }, 387 "slow_sql_time": "1000", 388 "black_sql": [ 389 "" 390 ], 391 "allowed_ip": null, 392 "slices": [ 393 { 394 "name": "slice-0", 395 "user_name": "root", 396 "password": "1234", 397 "master": "127.0.0.1:3307", 398 "slaves": [], 399 "statistic_slaves": null, 400 "capacity": 12, 401 "max_capacity": 24, 402 "idle_timeout": 60 403 }, 404 { 405 "name": "slice-1", 406 "user_name": "root", 407 "password": "1234", 408 "master": "127.0.0.1:3308", 409 "slaves": [], 410 "statistic_slaves": [], 411 "capacity": 12, 412 "max_capacity": 24, 413 "idle_timeout": 60 414 } 415 ], 416 "shard_rules": [ 417 { 418 "db": "db_kingshard", 419 "table": "shard_range", 420 "type": "range", 421 "key": "id", 422 "locations": [ 423 2, 424 2 425 ], 426 "slices": [ 427 "slice-0", 428 "slice-1" 429 ], 430 "table_row_limit": 3 431 } 432 ], 433 "users": [ 434 { 435 "user_name": "test", 436 "password": "1234", 437 "namespace": "test_kingshard_range", 438 "rw_flag": 2, 439 "rw_split": 1, 440 "other_property": 0 441 } 442 ], 443 "default_slice": "slice-1", 444 "global_sequences": null 445 } 446 ``` 447 其中,"table_row_limit:3"配置含义为:每张子表的记录数,分表字段位于区间[0,3)在shard_range_0000上,分表字段位于区间[3,6)在子表shard_range_0001上,依此类推... 448 449 ### 创建数据库表 450 ```shell script 451 #连接3307数据库实例 452 mysql -h127.0.0.1 -P3307 -uroot -p1234 453 #创建数据库 454 create database db_kingshard; 455 #在命令行执行以下命令,创建分表,shard_range_0000、shard_range_0001 456 for i in `seq 0 1`;do mysql -h127.0.0.1 -P3307 -uroot -p1234 db_kingshard -e "CREATE TABLE IF NOT EXISTS shard_range_000"${i}" ( id INT(64) NOT NULL, col1 VARCHAR(256),PRIMARY KEY (id)) ENGINE=InnoDB DEFAULT CHARSET=utf8;";done 457 458 #连接3306数据库实例 459 mysql -h127.0.0.1 -P3308 -uroot -p1234 460 #创建数据库 461 create database db_kingshard; 462 #在命令行执行以下命令,创建分表,shard_range_0002、shard_range_0003 463 for i in `seq 2 3`;do mysql -h127.0.0.1 -P3308 -uroot -p1234 db_kingshard -e "CREATE TABLE IF NOT EXISTS shard_range_000"${i}" ( id INT(64) NOT NULL, col1 VARCHAR(256),PRIMARY KEY (id)) ENGINE=InnoDB DEFAULT CHARSET=utf8;";done 464 #登录3307实例,查询slice-0分片表展示: 465 mysql> show tables; 466 +------------------------+ 467 | Tables_in_db_kingshard | 468 +------------------------+ 469 | shard_range_0000 | 470 | shard_range_0001 | 471 +------------------------+ 472 2 rows in set (0.00 sec) 473 474 #登录3308示例,查询slice-1分片表展示: 475 mysql> show tables; 476 +------------------------+ 477 | Tables_in_db_kingshard | 478 +------------------------+ 479 | shard_range_0002 | 480 | shard_range_0003 | 481 +------------------------+ 482 2 rows in set (0.01 sec) 483 ``` 484 485 ### 插入数据 486 ```shell script 487 #命令行执行,该命令连接Gaea执行插入: 488 for i in `seq 1 10`;do mysql -h127.0.0.1 -P13306 -utest -p1234 db_kingshard -e "insert into shard_range (id, col1) values(${i}, 'test$i')";done 489 ``` 490 491 ### 查看数据 492 ```shell script 493 #连接gaea,进行数据查询: 494 mysql> select * from shard_range; 495 +----+--------+ 496 | id | col1 | 497 +----+--------+ 498 | 1 | test1 | 499 | 2 | test2 | 500 | 3 | test3 | 501 | 4 | test4 | 502 | 5 | test5 | 503 | 6 | test6 | 504 | 7 | test7 | 505 | 8 | test8 | 506 | 9 | test9 | 507 | 10 | test10 | 508 +----+--------+ 509 10 rows in set (0.03 sec) 510 #连接3307数据库实例,对slice-0分表数据进行查询: 511 mysql> select * from shard_range_0000; 512 +----+-------+ 513 | id | col1 | 514 +----+-------+ 515 | 1 | test1 | 516 | 2 | test2 | 517 +----+-------+ 518 2 rows in set (0.01 sec) 519 mysql> select * from shard_range_0001; 520 +----+-------+ 521 | id | col1 | 522 +----+-------+ 523 | 3 | test3 | 524 | 4 | test4 | 525 | 5 | test5 | 526 +----+-------+ 527 3 rows in set (0.01 sec) 528 #连接3308数据库实例,对slice-1分表数据进行查询: 529 mysql> select * from shard_range_0002; 530 +----+-------+ 531 | id | col1 | 532 +----+-------+ 533 | 6 | test6 | 534 | 7 | test7 | 535 | 8 | test8 | 536 +----+-------+ 537 3 rows in set (0.01 sec) 538 mysql> select * from shard_range_0003; 539 +----+--------+ 540 | id | col1 | 541 +----+--------+ 542 | 9 | test9 | 543 | 10 | test10 | 544 +----+--------+ 545 2 rows in set (0.00 sec) 546 ``` 547 548 <h2 id="gaea_kingshard_date_year">gaea kingshard date year分片示例</h2> 549 550 我们预定义两个slice slice-0、slice-1,每个slice定义一个库,每个库预定义2张表,其中slice-0的主库地址为127.0.0.1:3307,slice-1的主库地址为127.0.0.1:3308。 551 552 Gaea启动地址为127.0.0.1:13307 553 554 ### namespace配置 555 ```json 556 { 557 "name": "test_kingshard_date_year", 558 "online": true, 559 "read_only": false, 560 "allowed_dbs": { 561 "db_kingshard": true 562 }, 563 "default_phy_dbs": { 564 "db_kingshard": "db_kingshard" 565 }, 566 "slow_sql_time": "1000", 567 "black_sql": [ 568 "" 569 ], 570 "allowed_ip": null, 571 "slices": [ 572 { 573 "name": "slice-0", 574 "user_name": "root", 575 "password": "1234", 576 "master": "127.0.0.1:3307", 577 "slaves": [], 578 "statistic_slaves": null, 579 "capacity": 12, 580 "max_capacity": 24, 581 "idle_timeout": 60 582 }, 583 { 584 "name": "slice-1", 585 "user_name": "root", 586 "password": "1234", 587 "master": "127.0.0.1:3308", 588 "slaves": [], 589 "statistic_slaves": [], 590 "capacity": 12, 591 "max_capacity": 24, 592 "idle_timeout": 60 593 } 594 ], 595 "shard_rules": [ 596 { 597 "db": "db_kingshard", 598 "table": "shard_year", 599 "type": "date_year", 600 "key": "create_time", 601 "slices": [ 602 "slice-0", 603 "slice-1" 604 ], 605 "date_range": [ 606 "2016-2017", 607 "2018-2019" 608 ] 609 } 610 ], 611 "users": [ 612 { 613 "user_name": "test", 614 "password": "1234", 615 "namespace": "test_kingshard_date_year", 616 "rw_flag": 2, 617 "rw_split": 1, 618 "other_property": 0 619 } 620 ], 621 "default_slice": "slice-1", 622 "global_sequences": null 623 } 624 ``` 625 626 ### 创建数据库表 627 ```shell script 628 #连接3307数据库实例 629 mysql -h127.0.0.1 -P3307 -uroot -p1234 630 #创建数据库 631 create database db_kingshard; 632 #在命令行执行以下命令,创建分表,shard_year_2016、shard_year_2017 633 for i in `seq 6 7`;do mysql -h127.0.0.1 -P3307 -uroot -p1234 db_kingshard -e "CREATE TABLE IF NOT EXISTS shard_year_201"${i}" ( id INT(64) NOT NULL, col1 VARCHAR(256),create_time datetime DEFAULT NULL,PRIMARY KEY (id)) ENGINE=InnoDB DEFAULT CHARSET=utf8;";done 634 635 #连接3306数据库实例 636 mysql -h127.0.0.1 -P3308 -uroot -p1234 637 #创建数据库 638 create database db_kingshard; 639 #在命令行执行以下命令,创建分表,shard_year_2018、shard_year_2019 640 for i in `seq 8 9`;do mysql -h127.0.0.1 -P3308 -uroot -p1234 db_kingshard -e "CREATE TABLE IF NOT EXISTS shard_year_201"${i}" ( id INT(64) NOT NULL, col1 VARCHAR(256),create_time datetime DEFAULT NULL,PRIMARY KEY (id)) ENGINE=InnoDB DEFAULT CHARSET=utf8;";done 641 #登录3307实例,查询slice-0分片表展示: 642 mysql> show tables; 643 +------------------------+ 644 | Tables_in_db_kingshard | 645 +------------------------+ 646 | shard_year_2016 | 647 | shard_year_2017 | 648 +------------------------+ 649 2 rows in set (0.00 sec) 650 651 #登录3308示例,查询slice-1分片表展示: 652 mysql> show tables; 653 +------------------------+ 654 | Tables_in_db_kingshard | 655 +------------------------+ 656 | shard_year_2018 | 657 | shard_year_2019 | 658 +------------------------+ 659 2 rows in set (0.01 sec) 660 ``` 661 662 ### 插入数据 663 ```shell script 664 #命令行执行,该命令连接Gaea执行插入: 665 for i in `seq 6 9`;do mysql -h127.0.0.1 -P13306 -utest -p1234 db_kingshard -e "insert into shard_year (id, col1,create_time) values(${i}, 'test$i','201$i-07-01')";done 666 ``` 667 668 ### 查看数据 669 ```shell script 670 #连接gaea,进行数据查询: 671 mysql> select * from shard_year; 672 +----+-------+---------------------+ 673 | id | col1 | create_time | 674 +----+-------+---------------------+ 675 | 6 | test6 | 2016-07-01 00:00:00 | 676 | 7 | test7 | 2017-07-01 00:00:00 | 677 | 8 | test8 | 2018-07-01 00:00:00 | 678 | 9 | test9 | 2019-07-01 00:00:00 | 679 +----+-------+---------------------+ 680 4 rows in set (0.03 sec) 681 682 #连接3307数据库实例,对slice-0分表数据进行查询: 683 mysql> select * from shard_year_2016; 684 +----+-------+---------------------+ 685 | id | col1 | create_time | 686 +----+-------+---------------------+ 687 | 6 | test6 | 2016-07-01 00:00:00 | 688 +----+-------+---------------------+ 689 1 row in set (0.01 sec) 690 mysql> select * from shard_year_2017; 691 +----+-------+---------------------+ 692 | id | col1 | create_time | 693 +----+-------+---------------------+ 694 | 7 | test7 | 2017-07-01 00:00:00 | 695 +----+-------+---------------------+ 696 1 row in set (0.01 sec) 697 #连接3308数据库实例,对slice-1分表数据进行查询: 698 mysql> select * from shard_year_2018; 699 +----+-------+---------------------+ 700 | id | col1 | create_time | 701 +----+-------+---------------------+ 702 | 8 | test8 | 2018-07-01 00:00:00 | 703 +----+-------+---------------------+ 704 1 row in set (0.01 sec) 705 mysql> select * from shard_year_2019; 706 +----+-------+---------------------+ 707 | id | col1 | create_time | 708 +----+-------+---------------------+ 709 | 9 | test9 | 2019-07-01 00:00:00 | 710 +----+-------+---------------------+ 711 1 row in set (0.00 sec) 712 ``` 713 714 715 <h2 id="gaea_kingshard_date_month">gaea kingshard date month分片示例</h2> 716 717 我们预定义两个slice slice-0、slice-1,每个slice定义一个库,每个库预定义2张表,其中slice-0的主库地址为127.0.0.1:3307,slice-1的主库地址为127.0.0.1:3308。 718 719 Gaea启动地址为127.0.0.1:13307 720 721 ### namespace配置 722 ```json 723 { 724 "name": "test_kingshard_date_month", 725 "online": true, 726 "read_only": false, 727 "allowed_dbs": { 728 "db_kingshard": true 729 }, 730 "default_phy_dbs": { 731 "db_kingshard": "db_kingshard" 732 }, 733 "slow_sql_time": "1000", 734 "black_sql": [ 735 "" 736 ], 737 "allowed_ip": null, 738 "slices": [ 739 { 740 "name": "slice-0", 741 "user_name": "root", 742 "password": "1234", 743 "master": "127.0.0.1:3307", 744 "slaves": [], 745 "statistic_slaves": null, 746 "capacity": 12, 747 "max_capacity": 24, 748 "idle_timeout": 60 749 }, 750 { 751 "name": "slice-1", 752 "user_name": "root", 753 "password": "1234", 754 "master": "127.0.0.1:3308", 755 "slaves": [], 756 "statistic_slaves": [], 757 "capacity": 12, 758 "max_capacity": 24, 759 "idle_timeout": 60 760 } 761 ], 762 "shard_rules": [ 763 { 764 "db": "db_kingshard", 765 "table": "shard_month", 766 "type": "date_month", 767 "key": "create_time", 768 "slices": [ 769 "slice-0", 770 "slice-1" 771 ], 772 "date_range": [ 773 "201405-201406", 774 "201408-201409" 775 ] 776 } 777 ], 778 "users": [ 779 { 780 "user_name": "test", 781 "password": "1234", 782 "namespace": "test_kingshard_date_month", 783 "rw_flag": 2, 784 "rw_split": 1, 785 "other_property": 0 786 } 787 ], 788 "default_slice": "slice-1", 789 "global_sequences": null 790 } 791 ``` 792 793 ### 创建数据库表 794 ```shell script 795 #连接3307数据库实例 796 mysql -h127.0.0.1 -P3307 -uroot -p1234 797 #创建数据库 798 create database db_kingshard; 799 #在命令行执行以下命令,创建分表,shard_month_201405、shard_month_201406 800 for i in `seq 5 6`;do mysql -h127.0.0.1 -P3307 -uroot -p1234 db_kingshard -e "CREATE TABLE IF NOT EXISTS shard_month_20140"${i}" ( id INT(64) NOT NULL, col1 VARCHAR(256),create_time datetime DEFAULT NULL,PRIMARY KEY (id)) ENGINE=InnoDB DEFAULT CHARSET=utf8;";done 801 802 #连接3306数据库实例 803 mysql -h127.0.0.1 -P3308 -uroot -p1234 804 #创建数据库 805 create database db_kingshard; 806 #在命令行执行以下命令,创建分表,shard_month_201408、shard_month_201409 807 for i in `seq 8 9`;do mysql -h127.0.0.1 -P3308 -uroot -p1234 db_kingshard -e "CREATE TABLE IF NOT EXISTS shard_month_20140"${i}" ( id INT(64) NOT NULL, col1 VARCHAR(256),create_time datetime DEFAULT NULL,PRIMARY KEY (id)) ENGINE=InnoDB DEFAULT CHARSET=utf8;";done 808 #登录3307实例,查询slice-0分片表展示: 809 mysql> show tables; 810 +------------------------+ 811 | Tables_in_db_kingshard | 812 +------------------------+ 813 | shard_month_201405 | 814 | shard_month_201406 | 815 +------------------------+ 816 2 rows in set (0.01 sec) 817 818 #登录3308示例,查询slice-1分片表展示: 819 mysql> show tables; 820 +------------------------+ 821 | Tables_in_db_kingshard | 822 +------------------------+ 823 | shard_month_201408 | 824 | shard_month_201409 | 825 +------------------------+ 826 2 rows in set (0.00 sec) 827 ``` 828 829 ### 插入数据 830 ```shell script 831 #命令行执行,该命令连接Gaea执行插入: 832 for i in `seq 5 6`;do mysql -h127.0.0.1 -P13306 -utest -p1234 db_kingshard -e "insert into shard_month (id, col1,create_time) values(${i}, 'test$i','2014-0$i-01')";done 833 for i in `seq 8 9`;do mysql -h127.0.0.1 -P13306 -utest -p1234 db_kingshard -e "insert into shard_month (id, col1,create_time) values(${i}, 'test$i','2014-0$i-01')";done 834 ``` 835 836 ### 查看数据 837 ```shell script 838 #连接gaea,进行数据查询: 839 mysql> select * from shard_month; 840 +----+-------+---------------------+ 841 | id | col1 | create_time | 842 +----+-------+---------------------+ 843 | 5 | test5 | 2014-05-01 00:00:00 | 844 | 6 | test6 | 2014-06-01 00:00:00 | 845 | 8 | test8 | 2014-08-01 00:00:00 | 846 | 9 | test9 | 2014-09-01 00:00:00 | 847 +----+-------+---------------------+ 848 4 rows in set (0.03 sec) 849 850 #连接3307数据库实例,对slice-0分表数据进行查询: 851 mysql> select * from shard_month_201405; 852 +----+-------+---------------------+ 853 | id | col1 | create_time | 854 +----+-------+---------------------+ 855 | 5 | test5 | 2014-05-01 00:00:00 | 856 +----+-------+---------------------+ 857 1 row in set (0.01 sec) 858 859 mysql> select * from shard_month_201406; 860 +----+-------+---------------------+ 861 | id | col1 | create_time | 862 +----+-------+---------------------+ 863 | 6 | test6 | 2014-06-01 00:00:00 | 864 +----+-------+---------------------+ 865 1 row in set (0.01 sec) 866 #连接3308数据库实例,对slice-1分表数据进行查询: 867 mysql> select * from shard_month_201408; 868 +----+-------+---------------------+ 869 | id | col1 | create_time | 870 +----+-------+---------------------+ 871 | 8 | test8 | 2014-08-01 00:00:00 | 872 +----+-------+---------------------+ 873 1 row in set (0.00 sec) 874 875 mysql> select * from shard_month_201409; 876 +----+-------+---------------------+ 877 | id | col1 | create_time | 878 +----+-------+---------------------+ 879 | 9 | test9 | 2014-09-01 00:00:00 | 880 +----+-------+---------------------+ 881 1 row in set (0.00 sec) 882 883 ``` 884 885 <h2 id="gaea_kingshard_date_day">gaea kingshard date day分片示例</h2> 886 887 我们预定义两个slice slice-0、slice-1,每个slice定义一个库,每个库预定义2张表,其中slice-0的主库地址为127.0.0.1:3307,slice-1的主库地址为127.0.0.1:3308。 888 889 Gaea启动地址为127.0.0.1:13307 890 891 ### namespace配置 892 ```json 893 { 894 "name": "test_kingshard_date_day", 895 "online": true, 896 "read_only": false, 897 "allowed_dbs": { 898 "db_kingshard": true 899 }, 900 "default_phy_dbs": { 901 "db_kingshard": "db_kingshard" 902 }, 903 "slow_sql_time": "1000", 904 "black_sql": [ 905 "" 906 ], 907 "allowed_ip": null, 908 "slices": [ 909 { 910 "name": "slice-0", 911 "user_name": "root", 912 "password": "1234", 913 "master": "127.0.0.1:3307", 914 "slaves": [], 915 "statistic_slaves": null, 916 "capacity": 12, 917 "max_capacity": 24, 918 "idle_timeout": 60 919 }, 920 { 921 "name": "slice-1", 922 "user_name": "root", 923 "password": "1234", 924 "master": "127.0.0.1:3308", 925 "slaves": [], 926 "statistic_slaves": [], 927 "capacity": 12, 928 "max_capacity": 24, 929 "idle_timeout": 60 930 } 931 ], 932 "shard_rules": [ 933 { 934 "db": "db_kingshard", 935 "table": "shard_day", 936 "type": "date_day", 937 "key": "create_time", 938 "slices": [ 939 "slice-0", 940 "slice-1" 941 ], 942 "date_range": [ 943 "20201201-20201202", 944 "20201203-20201204" 945 ] 946 } 947 ], 948 "users": [ 949 { 950 "user_name": "test", 951 "password": "1234", 952 "namespace": "test_kingshard_date_day", 953 "rw_flag": 2, 954 "rw_split": 1, 955 "other_property": 0 956 } 957 ], 958 "default_slice": "slice-1", 959 "global_sequences": null 960 } 961 ``` 962 963 ### 创建数据库表 964 ```shell script 965 #连接3307数据库实例 966 mysql -h127.0.0.1 -P3307 -uroot -p1234 967 #创建数据库 968 create database db_kingshard; 969 #在命令行执行以下命令,创建分表,shard_month_201405、shard_day_20201201、shard_day_20201202 970 for i in `seq 1 2`;do mysql -h127.0.0.1 -P3307 -uroot -p1234 db_kingshard -e "CREATE TABLE IF NOT EXISTS shard_day_2020120"${i}" ( id INT(64) NOT NULL, col1 VARCHAR(256),create_time datetime DEFAULT NULL,PRIMARY KEY (id)) ENGINE=InnoDB DEFAULT CHARSET=utf8;";done 971 972 #连接3306数据库实例 973 mysql -h127.0.0.1 -P3308 -uroot -p1234 974 #创建数据库 975 create database db_kingshard; 976 #在命令行执行以下命令,创建分表,shard_day_20201203、shard_day_20201204 977 for i in `seq 3 4`;do mysql -h127.0.0.1 -P3308 -uroot -p1234 db_kingshard -e "CREATE TABLE IF NOT EXISTS shard_day_2020120"${i}" ( id INT(64) NOT NULL, col1 VARCHAR(256),create_time datetime DEFAULT NULL,PRIMARY KEY (id)) ENGINE=InnoDB DEFAULT CHARSET=utf8;";done 978 #登录3307实例,查询slice-0分片表展示: 979 mysql> show tables; 980 +------------------------+ 981 | Tables_in_db_kingshard | 982 +------------------------+ 983 | shard_day_20201201 | 984 | shard_day_20201202 | 985 +------------------------+ 986 2 rows in set (0.00 sec) 987 988 #登录3308示例,查询slice-1分片表展示: 989 mysql> show tables; 990 +------------------------+ 991 | Tables_in_db_kingshard | 992 +------------------------+ 993 | shard_day_20201203 | 994 | shard_day_20201204 | 995 +------------------------+ 996 2 rows in set (0.00 sec) 997 ``` 998 999 ### 插入数据 1000 ```shell script 1001 #命令行执行,该命令连接Gaea执行插入: 1002 for i in `seq 1 4`;do mysql -h127.0.0.1 -P13306 -utest -p1234 db_kingshard -e "insert into shard_day (id, col1,create_time) values(${i}, 'test$i','2020-12-0$i')";done 1003 ``` 1004 1005 ### 查看数据 1006 ```shell script 1007 #连接gaea,进行数据查询: 1008 mysql> select * from shard_day; 1009 +----+-------+---------------------+ 1010 | id | col1 | create_time | 1011 +----+-------+---------------------+ 1012 | 1 | test1 | 2020-12-01 00:00:00 | 1013 | 2 | test2 | 2020-12-02 00:00:00 | 1014 | 3 | test3 | 2020-12-03 00:00:00 | 1015 | 4 | test4 | 2020-12-04 00:00:00 | 1016 +----+-------+---------------------+ 1017 4 rows in set (0.03 sec) 1018 1019 #连接3307数据库实例,对slice-0分表数据进行查询: 1020 mysql> select * from shard_day_20201201; 1021 +----+-------+---------------------+ 1022 | id | col1 | create_time | 1023 +----+-------+---------------------+ 1024 | 1 | test1 | 2020-12-01 00:00:00 | 1025 +----+-------+---------------------+ 1026 1 row in set (0.00 sec) 1027 1028 mysql> select * from shard_day_20201202; 1029 +----+-------+---------------------+ 1030 | id | col1 | create_time | 1031 +----+-------+---------------------+ 1032 | 2 | test2 | 2020-12-02 00:00:00 | 1033 +----+-------+---------------------+ 1034 1 row in set (0.01 sec) 1035 #连接3308数据库实例,对slice-1分表数据进行查询: 1036 mysql> select * from shard_day_20201203; 1037 +----+-------+---------------------+ 1038 | id | col1 | create_time | 1039 +----+-------+---------------------+ 1040 | 3 | test3 | 2020-12-03 00:00:00 | 1041 +----+-------+---------------------+ 1042 1 row in set (0.00 sec) 1043 1044 mysql> select * from shard_day_20201204; 1045 +----+-------+---------------------+ 1046 | id | col1 | create_time | 1047 +----+-------+---------------------+ 1048 | 4 | test4 | 2020-12-04 00:00:00 | 1049 +----+-------+---------------------+ 1050 1 row in set (0.01 sec) 1051 1052 ``` 1053 1054 <h2 id="gaea_mycat_mod">gaea mycat mod分片示例</h2> 1055 1056 我们预定义两个slice slice-0、slice-1,每个slice预定义2个库,每个库一张表,其中slice-0的主库地址为127.0.0.1:3307,slice-1的主库地址为127.0.0.1:3308。 1057 1058 Gaea启动地址为127.0.0.1:13307 1059 1060 ### namespace配置 1061 ```json 1062 { 1063 "name": "test_mycat_mod", 1064 "online": true, 1065 "read_only": false, 1066 "allowed_dbs": { 1067 "db_mycat": true 1068 }, 1069 "default_phy_dbs": { 1070 "db_mycat": "db_mycat" 1071 }, 1072 "slow_sql_time": "1000", 1073 "black_sql": [ 1074 "" 1075 ], 1076 "allowed_ip": null, 1077 "slices": [ 1078 { 1079 "name": "slice-0", 1080 "user_name": "root", 1081 "password": "1234", 1082 "master": "127.0.0.1:3307", 1083 "slaves": [], 1084 "statistic_slaves": null, 1085 "capacity": 12, 1086 "max_capacity": 24, 1087 "idle_timeout": 60 1088 }, 1089 { 1090 "name": "slice-1", 1091 "user_name": "root", 1092 "password": "1234", 1093 "master": "127.0.0.1:3308", 1094 "slaves": [], 1095 "statistic_slaves": [], 1096 "capacity": 12, 1097 "max_capacity": 24, 1098 "idle_timeout": 60 1099 } 1100 ], 1101 "shard_rules": [ 1102 { 1103 "db": "db_mycat", 1104 "table": "tbl_mycat", 1105 "type": "mycat_mod", 1106 "key": "id", 1107 "locations": [ 1108 2, 1109 2 1110 ], 1111 "slices": [ 1112 "slice-0", 1113 "slice-1" 1114 ], 1115 "databases": [ 1116 "db_mycat_[0-3]" 1117 ] 1118 } 1119 ], 1120 "users": [ 1121 { 1122 "user_name": "test", 1123 "password": "1234", 1124 "namespace": "test_mycat_mod", 1125 "rw_flag": 2, 1126 "rw_split": 1, 1127 "other_property": 0 1128 } 1129 ], 1130 "default_slice": "slice-1", 1131 "global_sequences": null 1132 } 1133 ``` 1134 1135 ### 创建数据库表 1136 ```shell script 1137 #连接3307数据库实例 1138 mysql -h127.0.0.1 -P3307 -uroot -p1234 1139 #创建数据库 1140 create database db_mycat_0; 1141 create database db_mycat_1; 1142 #在命令行执行以下命令,创建分表 1143 for i in `seq 0 1`;do mysql -h127.0.0.1 -P3307 -uroot -p1234 db_mycat_$i -e "CREATE TABLE IF NOT EXISTS tbl_mycat ( id INT(64) NOT NULL, col1 VARCHAR(256),PRIMARY KEY (id)) ENGINE=InnoDB DEFAULT CHARSET=utf8;";done 1144 1145 #连接3306数据库实例 1146 mysql -h127.0.0.1 -P3308 -uroot -p1234 1147 #创建数据库 1148 create database db_mycat_2; 1149 create database db_mycat_3; 1150 #在命令行执行以下命令,创建分表 1151 for i in `seq 2 3`;do mysql -h127.0.0.1 -P3308 -uroot -p1234 db_mycat_$i -e "CREATE TABLE IF NOT EXISTS tbl_mycat ( id INT(64) NOT NULL, col1 VARCHAR(256),PRIMARY KEY (id)) ENGINE=InnoDB DEFAULT CHARSET=utf8;";done 1152 #登录3307实例,查询slice-0分片表展示: 1153 mysql> use db_mycat_0; 1154 Reading table information for completion of table and column names 1155 You can turn off this feature to get a quicker startup with -A 1156 Database changed 1157 mysql> show tables; 1158 +----------------------+ 1159 | Tables_in_db_mycat_0 | 1160 +----------------------+ 1161 | tbl_mycat | 1162 +----------------------+ 1163 1 row in set (0.00 sec) 1164 mysql> use db_mycat_1 1165 Reading table information for completion of table and column names 1166 You can turn off this feature to get a quicker startup with -A 1167 Database changed 1168 mysql> show tables; 1169 +----------------------+ 1170 | Tables_in_db_mycat_1 | 1171 +----------------------+ 1172 | tbl_mycat | 1173 +----------------------+ 1174 1 row in set (0.01 sec) 1175 1176 #登录3308示例,查询slice-1分片表展示: 1177 mysql> use db_mycat_2; 1178 Reading table information for completion of table and column names 1179 You can turn off this feature to get a quicker startup with -A 1180 1181 Database changed 1182 mysql> show tables; 1183 +----------------------+ 1184 | Tables_in_db_mycat_2 | 1185 +----------------------+ 1186 | tbl_mycat | 1187 +----------------------+ 1188 1 row in set (0.00 sec) 1189 mysql> use db_mycat_3; 1190 Reading table information for completion of table and column names 1191 You can turn off this feature to get a quicker startup with -A 1192 Database changed 1193 mysql> show tables; 1194 +----------------------+ 1195 | Tables_in_db_mycat_3 | 1196 +----------------------+ 1197 | tbl_mycat | 1198 +----------------------+ 1199 1 row in set (0.00 sec) 1200 ``` 1201 1202 ### 插入数据 1203 ```shell script 1204 #命令行执行,该命令连接Gaea执行插入: 1205 for i in `seq 1 10`;do mysql -h127.0.0.1 -P13306 -utest -p1234 db_mycat -e "insert into tbl_mycat (id, col1) values(${i}, 'test$i')";done 1206 ``` 1207 1208 ### 查看数据 1209 ```shell script 1210 #连接gaea,进行数据查询: 1211 mysql> use db_mycat 1212 Database changed 1213 mysql> select * from tbl_mycat; 1214 +----+--------+ 1215 | id | col1 | 1216 +----+--------+ 1217 | 4 | test4 | 1218 | 8 | test8 | 1219 | 1 | test1 | 1220 | 5 | test5 | 1221 | 9 | test9 | 1222 | 3 | test3 | 1223 | 7 | test7 | 1224 | 2 | test2 | 1225 | 6 | test6 | 1226 | 10 | test10 | 1227 +----+--------+ 1228 10 rows in set (0.04 sec) 1229 1230 #连接3307数据库实例,对slice-0分片数据进行查询: 1231 mysql> use db_mycat_0; 1232 Reading table information for completion of table and column names 1233 You can turn off this feature to get a quicker startup with -A 1234 1235 Database changed 1236 mysql> select * from tbl_mycat; 1237 +----+-------+ 1238 | id | col1 | 1239 +----+-------+ 1240 | 4 | test4 | 1241 | 8 | test8 | 1242 +----+-------+ 1243 2 rows in set (0.01 sec) 1244 1245 mysql> use db_mycat_1; 1246 Reading table information for completion of table and column names 1247 You can turn off this feature to get a quicker startup with -A 1248 1249 Database changed 1250 mysql> select * from tbl_mycat; 1251 +----+-------+ 1252 | id | col1 | 1253 +----+-------+ 1254 | 1 | test1 | 1255 | 5 | test5 | 1256 | 9 | test9 | 1257 +----+-------+ 1258 3 rows in set (0.00 sec) 1259 #连接3308数据库实例,对slice-1分片数据进行查询: 1260 mysql> use db_mycat_2; 1261 Reading table information for completion of table and column names 1262 You can turn off this feature to get a quicker startup with -A 1263 1264 Database changed 1265 mysql> select * from tbl_mycat; 1266 +----+--------+ 1267 | id | col1 | 1268 +----+--------+ 1269 | 2 | test2 | 1270 | 6 | test6 | 1271 | 10 | test10 | 1272 +----+--------+ 1273 3 rows in set (0.01 sec) 1274 1275 mysql> use db_mycat_3; 1276 Reading table information for completion of table and column names 1277 You can turn off this feature to get a quicker startup with -A 1278 1279 Database changed 1280 mysql> select * from tbl_mycat; 1281 +----+-------+ 1282 | id | col1 | 1283 +----+-------+ 1284 | 3 | test3 | 1285 | 7 | test7 | 1286 +----+-------+ 1287 2 rows in set (0.01 sec) 1288 ``` 1289 1290 <h2 id="gaea_mycat_long">gaea mycat_long(固定hash分片算法)分片示例</h2> 1291 1292 我们预定义两个slice slice-0、slice-1,每个slice预定义2个库,每个库一张表,其中slice-0的主库地址为127.0.0.1:3307,slice-1的主库地址为127.0.0.1:3308。 1293 1294 Gaea启动地址为127.0.0.1:13307 1295 1296 ### namespace配置 1297 ```json 1298 { 1299 "name": "test_mycat_long", 1300 "online": true, 1301 "read_only": false, 1302 "allowed_dbs": { 1303 "db_mycat": true 1304 }, 1305 "default_phy_dbs": { 1306 "db_mycat": "db_mycat" 1307 }, 1308 "slow_sql_time": "1000", 1309 "black_sql": [ 1310 "" 1311 ], 1312 "allowed_ip": null, 1313 "slices": [ 1314 { 1315 "name": "slice-0", 1316 "user_name": "root", 1317 "password": "1234", 1318 "master": "127.0.0.1:3307", 1319 "slaves": [], 1320 "statistic_slaves": null, 1321 "capacity": 12, 1322 "max_capacity": 24, 1323 "idle_timeout": 60 1324 }, 1325 { 1326 "name": "slice-1", 1327 "user_name": "root", 1328 "password": "1234", 1329 "master": "127.0.0.1:3308", 1330 "slaves": [], 1331 "statistic_slaves": [], 1332 "capacity": 12, 1333 "max_capacity": 24, 1334 "idle_timeout": 60 1335 } 1336 ], 1337 "shard_rules": [ 1338 { 1339 "db": "db_mycat", 1340 "table": "tbl_mycat", 1341 "type": "mycat_long", 1342 "key": "id", 1343 "locations": [ 1344 2, 1345 2 1346 ], 1347 "slices": [ 1348 "slice-0", 1349 "slice-1" 1350 ], 1351 "databases": [ 1352 "db_mycat_[0-3]" 1353 ], 1354 "partition_count": "4", 1355 "partition_length": "256" 1356 } 1357 ], 1358 "users": [ 1359 { 1360 "user_name": "test", 1361 "password": "1234", 1362 "namespace": "test_mycat_long", 1363 "rw_flag": 2, 1364 "rw_split": 1, 1365 "other_property": 0 1366 } 1367 ], 1368 "default_slice": "slice-1", 1369 "global_sequences": null 1370 } 1371 ``` 1372 1373 ### 创建数据库表 1374 ```shell script 1375 #连接3307数据库实例 1376 mysql -h127.0.0.1 -P3307 -uroot -p1234 1377 #创建数据库 1378 create database db_mycat_0; 1379 create database db_mycat_1; 1380 #在命令行执行以下命令,创建分表 1381 for i in `seq 0 1`;do mysql -h127.0.0.1 -P3307 -uroot -p1234 db_mycat_$i -e "CREATE TABLE IF NOT EXISTS tbl_mycat ( id INT(64) NOT NULL, col1 VARCHAR(256),PRIMARY KEY (id)) ENGINE=InnoDB DEFAULT CHARSET=utf8;";done 1382 1383 #连接3306数据库实例 1384 mysql -h127.0.0.1 -P3308 -uroot -p1234 1385 #创建数据库 1386 create database db_mycat_2; 1387 create database db_mycat_3; 1388 #在命令行执行以下命令,创建分表 1389 for i in `seq 2 3`;do mysql -h127.0.0.1 -P3308 -uroot -p1234 db_mycat_$i -e "CREATE TABLE IF NOT EXISTS tbl_mycat ( id INT(64) NOT NULL, col1 VARCHAR(256),PRIMARY KEY (id)) ENGINE=InnoDB DEFAULT CHARSET=utf8;";done 1390 #登录3307实例,查询slice-0分片表展示: 1391 mysql> use db_mycat_0; 1392 Reading table information for completion of table and column names 1393 You can turn off this feature to get a quicker startup with -A 1394 Database changed 1395 mysql> show tables; 1396 +----------------------+ 1397 | Tables_in_db_mycat_0 | 1398 +----------------------+ 1399 | tbl_mycat | 1400 +----------------------+ 1401 1 row in set (0.00 sec) 1402 mysql> use db_mycat_1 1403 Reading table information for completion of table and column names 1404 You can turn off this feature to get a quicker startup with -A 1405 Database changed 1406 mysql> show tables; 1407 +----------------------+ 1408 | Tables_in_db_mycat_1 | 1409 +----------------------+ 1410 | tbl_mycat | 1411 +----------------------+ 1412 1 row in set (0.01 sec) 1413 1414 #登录3308示例,查询slice-1分片表展示: 1415 mysql> use db_mycat_2; 1416 Reading table information for completion of table and column names 1417 You can turn off this feature to get a quicker startup with -A 1418 1419 Database changed 1420 mysql> show tables; 1421 +----------------------+ 1422 | Tables_in_db_mycat_2 | 1423 +----------------------+ 1424 | tbl_mycat | 1425 +----------------------+ 1426 1 row in set (0.00 sec) 1427 mysql> use db_mycat_3; 1428 Reading table information for completion of table and column names 1429 You can turn off this feature to get a quicker startup with -A 1430 Database changed 1431 mysql> show tables; 1432 +----------------------+ 1433 | Tables_in_db_mycat_3 | 1434 +----------------------+ 1435 | tbl_mycat | 1436 +----------------------+ 1437 1 row in set (0.00 sec) 1438 ``` 1439 1440 ### 插入数据 1441 ```shell script 1442 #命令行执行,该命令连接Gaea执行插入,插入2000行记录。 1443 for i in `seq 1 2000`;do mysql -h127.0.0.1 -P13306 -utest -p1234 db_mycat -e "insert into tbl_mycat (id, col1) values(${i}, 'test$i')";done 1444 ``` 1445 1446 ### 查看数据 1447 ```shell script 1448 #连接gaea,进行数据查询: 1449 mysql> use db_mycat 1450 Database changed 1451 mysql> select * from tbl_mycat; 1452 +------+----------+ 1453 | id | col1 | 1454 +------+----------+ 1455 | 1 | test1 | 1456 | 2 | test2 | 1457 | 3 | test3 | 1458 ................... 1459 | 1786 | test1786 | 1460 | 1787 | test1787 | 1461 | 1788 | test1788 | 1462 | 1789 | test1789 | 1463 | 1790 | test1790 | 1464 | 1791 | test1791 | 1465 +------+----------+ 1466 2000 rows in set (0.61 sec) 1467 #连接3307数据库实例,对slice-0分片数据进行查询: 1468 mysql> use db_mycat_0; 1469 Database changed 1470 mysql> select * from tbl_mycat; 1471 +------+----------+ 1472 | id | col1 | 1473 +------+----------+ 1474 | 1 | test1 | 1475 | 2 | test2 | 1476 | 3 | test3 | 1477 .................. 1478 | 249 | test249 | 1479 | 250 | test250 | 1480 | 251 | test251 | 1481 | 252 | test252 | 1482 | 253 | test253 | 1483 | 254 | test254 | 1484 | 255 | test255 | 1485 | 1024 | test1024 | 1486 | 1025 | test1025 | 1487 | 1026 | test1026 | 1488 | 1027 | test1027 | 1489 | 1028 | test1028 | 1490 .................. 1491 | 1277 | test1277 | 1492 | 1278 | test1278 | 1493 | 1279 | test1279 | 1494 +------+----------+ 1495 511 rows in set (0.01 sec) 1496 1497 mysql> use db_mycat_1; 1498 Reading table information for completion of table and column names 1499 You can turn off this feature to get a quicker startup with -A 1500 1501 Database changed 1502 mysql> select * from tbl_mycat; 1503 +------+----------+ 1504 | id | col1 | 1505 +------+----------+ 1506 | 256 | test256 | 1507 | 257 | test257 | 1508 | 258 | test258 | 1509 | 259 | test259 | 1510 | 260 | test260 | 1511 ................... 1512 | 509 | test509 | 1513 | 510 | test510 | 1514 | 511 | test511 | 1515 | 1280 | test1280 | 1516 | 1281 | test1281 | 1517 | 1282 | test1282 | 1518 | 1283 | test1283 | 1519 | 1284 | test1284 | 1520 | 1285 | test1285 | 1521 ................... 1522 | 1532 | test1532 | 1523 | 1533 | test1533 | 1524 | 1534 | test1534 | 1525 | 1535 | test1535 | 1526 +------+----------+ 1527 512 rows in set (0.00 sec) 1528 #连接3308数据库实例,对slice-1分片数据进行查询: 1529 mysql> use db_mycat_2; 1530 Reading table information for completion of table and column names 1531 You can turn off this feature to get a quicker startup with -A 1532 1533 Database changed 1534 mysql> select * from tbl_mycat; 1535 +------+----------+ 1536 | id | col1 | 1537 +------+----------+ 1538 | 512 | test512 | 1539 | 513 | test513 | 1540 | 514 | test514 | 1541 | 515 | test515 | 1542 ................... 1543 | 765 | test765 | 1544 | 766 | test766 | 1545 | 767 | test767 | 1546 | 1536 | test1536 | 1547 | 1537 | test1537 | 1548 | 1538 | test1538 | 1549 | 1539 | test1539 | 1550 | 1540 | test1540 | 1551 ................... 1552 | 1786 | test1786 | 1553 | 1787 | test1787 | 1554 | 1788 | test1788 | 1555 | 1789 | test1789 | 1556 | 1790 | test1790 | 1557 | 1791 | test1791 | 1558 +------+----------+ 1559 512 rows in set (0.01 sec) 1560 1561 mysql> use db_mycat_3; 1562 Reading table information for completion of table and column names 1563 You can turn off this feature to get a quicker startup with -A 1564 1565 Database changed 1566 mysql> select * from tbl_mycat; 1567 +------+----------+ 1568 | id | col1 | 1569 +------+----------+ 1570 | 768 | test768 | 1571 | 769 | test769 | 1572 | 770 | test770 | 1573 | 771 | test771 | 1574 | 772 | test772 | 1575 | 773 | test773 | 1576 ................... 1577 | 996 | test996 | 1578 | 997 | test997 | 1579 | 998 | test998 | 1580 | 999 | test999 | 1581 | 1000 | test1000 | 1582 | 1001 | test1001 | 1583 | 1002 | test1002 | 1584 | 1003 | test1003 | 1585 | 1004 | test1004 | 1586 ................... 1587 | 1993 | test1993 | 1588 | 1994 | test1994 | 1589 | 1995 | test1995 | 1590 | 1996 | test1996 | 1591 | 1997 | test1997 | 1592 | 1998 | test1998 | 1593 | 1999 | test1999 | 1594 | 2000 | test2000 | 1595 +------+----------+ 1596 465 rows in set (0.00 sec) 1597 ``` 1598 1599 <h2 id="gaea_mycat_partitionByMurmurHash">gaea mycat_murmur(一致性Hash)分片示例</h2> 1600 1601 我们预定义两个slice slice-0、slice-1,每个slice预定义2个库,每个库一张表,其中slice-0的主库地址为127.0.0.1:3307,slice-1的主库地址为127.0.0.1:3308。 1602 1603 Gaea启动地址为127.0.0.1:13307 1604 1605 ### namespace配置 1606 ```json 1607 { 1608 "name": "test_mycat_murmur", 1609 "online": true, 1610 "read_only": false, 1611 "allowed_dbs": { 1612 "db_mycat": true 1613 }, 1614 "default_phy_dbs": { 1615 "db_mycat": "db_mycat" 1616 }, 1617 "slow_sql_time": "1000", 1618 "black_sql": [ 1619 "" 1620 ], 1621 "allowed_ip": null, 1622 "slices": [ 1623 { 1624 "name": "slice-0", 1625 "user_name": "root", 1626 "password": "1234", 1627 "master": "127.0.0.1:3307", 1628 "slaves": [], 1629 "statistic_slaves": null, 1630 "capacity": 12, 1631 "max_capacity": 24, 1632 "idle_timeout": 60 1633 }, 1634 { 1635 "name": "slice-1", 1636 "user_name": "root", 1637 "password": "1234", 1638 "master": "127.0.0.1:3308", 1639 "slaves": [], 1640 "statistic_slaves": [], 1641 "capacity": 12, 1642 "max_capacity": 24, 1643 "idle_timeout": 60 1644 } 1645 ], 1646 "shard_rules": [ 1647 { 1648 "db": "db_mycat", 1649 "table": "tbl_mycat", 1650 "type": "mycat_murmur", 1651 "key": "id", 1652 "locations": [ 1653 2, 1654 2 1655 ], 1656 "slices": [ 1657 "slice-0", 1658 "slice-1" 1659 ], 1660 "databases": [ 1661 "db_mycat_[0-3]" 1662 ], 1663 "seed": "0", 1664 "virtual_bucket_times": "160" 1665 } 1666 ], 1667 "users": [ 1668 { 1669 "user_name": "mycatMurmur", 1670 "password": "1234", 1671 "namespace": "test_mycat_murmur", 1672 "rw_flag": 2, 1673 "rw_split": 1, 1674 "other_property": 0 1675 } 1676 ], 1677 "default_slice": "slice-1", 1678 "global_sequences": null 1679 } 1680 ``` 1681 1682 ### 创建数据库表 1683 ```shell script 1684 #连接3307数据库实例 1685 mysql -h127.0.0.1 -P3307 -uroot -p1234 1686 #创建数据库 1687 create database db_mycat_0; 1688 create database db_mycat_1; 1689 #在命令行执行以下命令,创建分表 1690 for i in `seq 0 1`;do mysql -h127.0.0.1 -P3307 -uroot -p1234 db_mycat_$i -e "CREATE TABLE IF NOT EXISTS tbl_mycat ( id INT(64) NOT NULL, col1 VARCHAR(256),PRIMARY KEY (id)) ENGINE=InnoDB DEFAULT CHARSET=utf8;";done 1691 1692 #连接3306数据库实例 1693 mysql -h127.0.0.1 -P3308 -uroot -p1234 1694 #创建数据库 1695 create database db_mycat_2; 1696 create database db_mycat_3; 1697 #在命令行执行以下命令,创建分表 1698 for i in `seq 2 3`;do mysql -h127.0.0.1 -P3308 -uroot -p1234 db_mycat_$i -e "CREATE TABLE IF NOT EXISTS tbl_mycat ( id INT(64) NOT NULL, col1 VARCHAR(256),PRIMARY KEY (id)) ENGINE=InnoDB DEFAULT CHARSET=utf8;";done 1699 #登录3307实例,查询slice-0分片表展示: 1700 mysql> use db_mycat_0; 1701 Reading table information for completion of table and column names 1702 You can turn off this feature to get a quicker startup with -A 1703 Database changed 1704 mysql> show tables; 1705 +----------------------+ 1706 | Tables_in_db_mycat_0 | 1707 +----------------------+ 1708 | tbl_mycat | 1709 +----------------------+ 1710 1 row in set (0.00 sec) 1711 mysql> use db_mycat_1 1712 Reading table information for completion of table and column names 1713 You can turn off this feature to get a quicker startup with -A 1714 Database changed 1715 mysql> show tables; 1716 +----------------------+ 1717 | Tables_in_db_mycat_1 | 1718 +----------------------+ 1719 | tbl_mycat | 1720 +----------------------+ 1721 1 row in set (0.01 sec) 1722 1723 #登录3308示例,查询slice-1分片表展示: 1724 mysql> use db_mycat_2; 1725 Reading table information for completion of table and column names 1726 You can turn off this feature to get a quicker startup with -A 1727 1728 Database changed 1729 mysql> show tables; 1730 +----------------------+ 1731 | Tables_in_db_mycat_2 | 1732 +----------------------+ 1733 | tbl_mycat | 1734 +----------------------+ 1735 1 row in set (0.00 sec) 1736 mysql> use db_mycat_3; 1737 Reading table information for completion of table and column names 1738 You can turn off this feature to get a quicker startup with -A 1739 Database changed 1740 mysql> show tables; 1741 +----------------------+ 1742 | Tables_in_db_mycat_3 | 1743 +----------------------+ 1744 | tbl_mycat | 1745 +----------------------+ 1746 1 row in set (0.00 sec) 1747 ``` 1748 1749 ### 插入数据 1750 ```shell script 1751 #命令行执行,该命令连接Gaea执行插入: 1752 for i in `seq 1 2000`;do mysql -h127.0.0.1 -P13306 -utest -p1234 db_mycat -e "insert into tbl_mycat (id, col1) values(${i}, 'test$i')";done 1753 ``` 1754 1755 ### 查看数据 1756 ```shell script 1757 #连接gaea,进行数据查询: 1758 mysql> use db_mycat 1759 Database changed 1760 mysql> select * from tbl_mycat; 1761 +------+----------+ 1762 | id | col1 | 1763 +------+----------+ 1764 | 1 | test1 | 1765 | 2 | test2 | 1766 | 3 | test3 | 1767 | 9 | test9 | 1768 | 10 | test10 | 1769 | 15 | test15 | 1770 .................. 1771 | 1982 | test1982 | 1772 | 1987 | test1987 | 1773 | 1988 | test1988 | 1774 | 1990 | test1990 | 1775 | 1997 | test1997 | 1776 | 1999 | test1999 | 1777 +------+----------+ 1778 2000 rows in set (0.05 sec) 1779 1780 #连接3307数据库实例,对slice-0分片数据进行查询: 1781 mysql> use db_mycat_0; 1782 Reading table information for completion of table and column names 1783 You can turn off this feature to get a quicker startup with -A 1784 1785 Database changed 1786 mysql> select * from tbl_mycat; 1787 +------+----------+ 1788 | id | col1 | 1789 +------+----------+ 1790 | 5 | test5 | 1791 | 6 | test6 | 1792 | 8 | test8 | 1793 | 14 | test14 | 1794 | 16 | test16 | 1795 ................... 1796 | 1984 | test1984 | 1797 | 1989 | test1989 | 1798 | 1992 | test1992 | 1799 | 1998 | test1998 | 1800 | 2000 | test2000 | 1801 +------+----------+ 1802 522 rows in set (0.01 sec) 1803 1804 mysql> use db_mycat_1; 1805 Reading table information for completion of table and column names 1806 You can turn off this feature to get a quicker startup with -A 1807 1808 Database changed 1809 mysql> select * from tbl_mycat; 1810 +------+----------+ 1811 | id | col1 | 1812 +------+----------+ 1813 | 1 | test1 | 1814 | 2 | test2 | 1815 | 3 | test3 | 1816 | 9 | test9 | 1817 | 10 | test10 | 1818 | 15 | test15 | 1819 ................... 1820 | 1973 | test1973 | 1821 | 1976 | test1976 | 1822 | 1979 | test1979 | 1823 | 1983 | test1983 | 1824 | 1985 | test1985 | 1825 | 1993 | test1993 | 1826 +------+----------+ 1827 502 rows in set (0.01 sec) 1828 #连接3308数据库实例,对slice-1分片数据进行查询: 1829 mysql> use db_mycat_2; 1830 Reading table information for completion of table and column names 1831 You can turn off this feature to get a quicker startup with -A 1832 1833 Database changed 1834 mysql> select * from tbl_mycat; 1835 +------+----------+ 1836 | id | col1 | 1837 +------+----------+ 1838 | 4 | test4 | 1839 | 7 | test7 | 1840 | 11 | test11 | 1841 | 24 | test24 | 1842 | 30 | test30 | 1843 ................... 1844 | 1974 | test1974 | 1845 | 1986 | test1986 | 1846 | 1991 | test1991 | 1847 | 1994 | test1994 | 1848 | 1995 | test1995 | 1849 | 1996 | test1996 | 1850 +------+----------+ 1851 457 rows in set (0.01 sec) 1852 1853 mysql> use db_mycat_3; 1854 Reading table information for completion of table and column names 1855 You can turn off this feature to get a quicker startup with -A 1856 1857 Database changed 1858 mysql> select * from tbl_mycat; 1859 +------+----------+ 1860 | id | col1 | 1861 +------+----------+ 1862 | 12 | test12 | 1863 | 13 | test13 | 1864 | 20 | test20 | 1865 | 22 | test22 | 1866 ................... 1867 | 1982 | test1982 | 1868 | 1987 | test1987 | 1869 | 1988 | test1988 | 1870 | 1990 | test1990 | 1871 | 1997 | test1997 | 1872 | 1999 | test1999 | 1873 +------+----------+ 1874 519 rows in set (0.01 sec) 1875 ``` 1876 1877 <h2 id="gaea_mycat_partitionByString">gaea mycat_string(字符串拆分hash)分片示例</h2> 1878 1879 我们预定义两个slice slice-0、slice-1,每个slice预定义2个库,每个库一张表,其中slice-0的主库地址为127.0.0.1:3307,slice-1的主库地址为127.0.0.1:3308。 1880 1881 Gaea启动地址为127.0.0.1:13307 1882 1883 ### namespace配置 1884 ```json 1885 { 1886 "name": "test_mycat_string", 1887 "online": true, 1888 "read_only": false, 1889 "allowed_dbs": { 1890 "db_mycat": true 1891 }, 1892 "default_phy_dbs": { 1893 "db_mycat": "db_mycat" 1894 }, 1895 "slow_sql_time": "1000", 1896 "black_sql": [ 1897 "" 1898 ], 1899 "allowed_ip": null, 1900 "slices": [ 1901 { 1902 "name": "slice-0", 1903 "user_name": "root", 1904 "password": "1234", 1905 "master": "127.0.0.1:3307", 1906 "slaves": [], 1907 "statistic_slaves": null, 1908 "capacity": 12, 1909 "max_capacity": 24, 1910 "idle_timeout": 60 1911 }, 1912 { 1913 "name": "slice-1", 1914 "user_name": "root", 1915 "password": "1234", 1916 "master": "127.0.0.1:3308", 1917 "slaves": [], 1918 "statistic_slaves": [], 1919 "capacity": 12, 1920 "max_capacity": 24, 1921 "idle_timeout": 60 1922 } 1923 ], 1924 "shard_rules": [ 1925 { 1926 "db": "db_mycat", 1927 "table": "tbl_mycat", 1928 "type": "mycat_string", 1929 "key": "col1", 1930 "locations": [ 1931 2, 1932 2 1933 ], 1934 "slices": [ 1935 "slice-0", 1936 "slice-1" 1937 ], 1938 "databases": [ 1939 "db_mycat_[0-3]" 1940 ], 1941 "partition_count": "4", 1942 "partition_length": "256", 1943 "hash_slice": ":" 1944 } 1945 ], 1946 "users": [ 1947 { 1948 "user_name": "testMycatString", 1949 "password": "1234", 1950 "namespace": "test_mycat_string", 1951 "rw_flag": 2, 1952 "rw_split": 1, 1953 "other_property": 0 1954 } 1955 ], 1956 "default_slice": "slice-1", 1957 "global_sequences": null 1958 } 1959 1960 ``` 1961 1962 ### 创建数据库表 1963 ```shell script 1964 #连接3307数据库实例 1965 mysql -h127.0.0.1 -P3307 -uroot -p1234 1966 #创建数据库 1967 create database db_mycat_0; 1968 create database db_mycat_1; 1969 #在命令行执行以下命令,创建分表 1970 for i in `seq 0 1`;do mysql -h127.0.0.1 -P3307 -uroot -p1234 db_mycat_$i -e "CREATE TABLE IF NOT EXISTS tbl_mycat ( id INT(64) NOT NULL, col1 VARCHAR(256),PRIMARY KEY (id)) ENGINE=InnoDB DEFAULT CHARSET=utf8;";done 1971 1972 #连接3306数据库实例 1973 mysql -h127.0.0.1 -P3308 -uroot -p1234 1974 #创建数据库 1975 create database db_mycat_2; 1976 create database db_mycat_3; 1977 #在命令行执行以下命令,创建分表 1978 for i in `seq 2 3`;do mysql -h127.0.0.1 -P3308 -uroot -p1234 db_mycat_$i -e "CREATE TABLE IF NOT EXISTS tbl_mycat ( id INT(64) NOT NULL, col1 VARCHAR(256),PRIMARY KEY (id)) ENGINE=InnoDB DEFAULT CHARSET=utf8;";done 1979 #登录3307实例,查询slice-0分片表展示: 1980 mysql> use db_mycat_0; 1981 Reading table information for completion of table and column names 1982 You can turn off this feature to get a quicker startup with -A 1983 Database changed 1984 mysql> show tables; 1985 +----------------------+ 1986 | Tables_in_db_mycat_0 | 1987 +----------------------+ 1988 | tbl_mycat | 1989 +----------------------+ 1990 1 row in set (0.00 sec) 1991 mysql> use db_mycat_1 1992 Reading table information for completion of table and column names 1993 You can turn off this feature to get a quicker startup with -A 1994 Database changed 1995 mysql> show tables; 1996 +----------------------+ 1997 | Tables_in_db_mycat_1 | 1998 +----------------------+ 1999 | tbl_mycat | 2000 +----------------------+ 2001 1 row in set (0.01 sec) 2002 2003 #登录3308示例,查询slice-1分片表展示: 2004 mysql> use db_mycat_2; 2005 Reading table information for completion of table and column names 2006 You can turn off this feature to get a quicker startup with -A 2007 2008 Database changed 2009 mysql> show tables; 2010 +----------------------+ 2011 | Tables_in_db_mycat_2 | 2012 +----------------------+ 2013 | tbl_mycat | 2014 +----------------------+ 2015 1 row in set (0.00 sec) 2016 mysql> use db_mycat_3; 2017 Reading table information for completion of table and column names 2018 You can turn off this feature to get a quicker startup with -A 2019 Database changed 2020 mysql> show tables; 2021 +----------------------+ 2022 | Tables_in_db_mycat_3 | 2023 +----------------------+ 2024 | tbl_mycat | 2025 +----------------------+ 2026 1 row in set (0.00 sec) 2027 ``` 2028 2029 ### 插入数据 2030 ```shell script 2031 #命令行执行,该命令连接Gaea执行插入: 2032 for i in `seq 1 2000`;do mysql -h127.0.0.1 -P13306 -utest -p1234 db_mycat -e "insert into tbl_mycat (id, col1) values(${i}, 'test$i')";done 2033 ``` 2034 2035 ### 查看数据 2036 ```shell script 2037 #连接gaea,进行数据查询: 2038 mysql> use db_mycat 2039 Database changed 2040 mysql> select * from tbl_mycat; 2041 +------+----------+ 2042 | id | col1 | 2043 +------+----------+ 2044 | 50 | test50 | 2045 | 51 | test51 | 2046 | 52 | test52 | 2047 ................... 2048 | 1996 | test1996 | 2049 | 1997 | test1997 | 2050 | 1998 | test1998 | 2051 | 1999 | test1999 | 2052 +------+----------+ 2053 2000 rows in set (0.03 sec) 2054 2055 #连接3307数据库实例,对slice-0分片数据进行查询: 2056 mysql> use db_mycat_0; 2057 Reading table information for completion of table and column names 2058 You can turn off this feature to get a quicker startup with -A 2059 2060 Database changed 2061 mysql> select * from tbl_mycat; 2062 +------+----------+ 2063 | id | col1 | 2064 +------+----------+ 2065 | 500 | test500 | 2066 | 501 | test501 | 2067 | 502 | test502 | 2068 | 503 | test503 | 2069 ................... 2070 | 1985 | test1985 | 2071 | 1986 | test1986 | 2072 | 1987 | test1987 | 2073 | 1988 | test1988 | 2074 | 1989 | test1989 | 2075 +------+----------+ 2076 486 rows in set (0.01 sec) 2077 mysql> use db_mycat_1; 2078 Reading table information for completion of table and column names 2079 You can turn off this feature to get a quicker startup with -A 2080 2081 Database changed 2082 mysql> select * from tbl_mycat; 2083 +------+----------+ 2084 | id | col1 | 2085 +------+----------+ 2086 | 1 | test1 | 2087 | 2 | test2 | 2088 | 3 | test3 | 2089 ................... 2090 | 1995 | test1995 | 2091 | 1996 | test1996 | 2092 | 1997 | test1997 | 2093 | 1998 | test1998 | 2094 | 1999 | test1999 | 2095 +------+----------+ 2096 849 rows in set (0.01 sec) 2097 #连接3308数据库实例,对slice-1分片数据进行查询: 2098 mysql> use db_mycat_2; 2099 Reading table information for completion of table and column names 2100 You can turn off this feature to get a quicker startup with -A 2101 2102 Database changed 2103 mysql> select * from tbl_mycat; 2104 +------+----------+ 2105 | id | col1 | 2106 +------+----------+ 2107 | 50 | test50 | 2108 | 51 | test51 | 2109 | 52 | test52 | 2110 ................... 2111 | 1594 | test1594 | 2112 | 1595 | test1595 | 2113 | 1596 | test1596 | 2114 | 1597 | test1597 | 2115 | 1598 | test1598 | 2116 | 1599 | test1599 | 2117 | 2000 | test2000 | 2118 +------+----------+ 2119 601 rows in set (0.01 sec) 2120 2121 mysql> use db_mycat_3; 2122 Reading table information for completion of table and column names 2123 You can turn off this feature to get a quicker startup with -A 2124 2125 Database changed 2126 mysql> select * from tbl_mycat; 2127 +------+----------+ 2128 | id | col1 | 2129 +------+----------+ 2130 | 190 | test190 | 2131 | 191 | test191 | 2132 | 192 | test192 | 2133 | 193 | test193 | 2134 | 194 | test194 | 2135 ................... 2136 | 1900 | test1900 | 2137 | 1901 | test1901 | 2138 | 1902 | test1902 | 2139 | 1903 | test1903 | 2140 | 1904 | test1904 | 2141 | 1905 | test1905 | 2142 | 1906 | test1906 | 2143 +------+----------+ 2144 64 rows in set (0.00 sec) 2145 ```