数据分片

存储单元操作

  1. REGISTER STORAGE UNIT ds_0 (
  2. HOST="127.0.0.1",
  3. PORT=3306,
  4. DB="ds_1",
  5. USER="root",
  6. PASSWORD="root"
  7. ),ds_1 (
  8. HOST="127.0.0.1",
  9. PORT=3306,
  10. DB="ds_2",
  11. USER="root",
  12. PASSWORD="root"
  13. );

规则操作

  • 创建分片规则
  1. CREATE SHARDING TABLE RULE t_order(
  2. STORAGE_UNITS(ds_0,ds_1),
  3. SHARDING_COLUMN=order_id,
  4. TYPE(NAME="hash_mod",PROPERTIES("sharding-count"="4")),
  5. KEY_GENERATE_STRATEGY(COLUMN=order_id,TYPE(NAME="snowflake"))
  6. );
  • 创建切分表
  1. CREATE TABLE `t_order` (
  2. `order_id` int NOT NULL,
  3. `user_id` int NOT NULL,
  4. `status` varchar(45) DEFAULT NULL,
  5. PRIMARY KEY (`order_id`)
  6. ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4
  • 删除切分表
  1. DROP TABLE t_order;
  • 删除分片规则
  1. DROP SHARDING TABLE RULE t_order;
  • 移除数据源
  1. UNREGISTER STORAGE UNIT ds_0, ds_1;
  • 删除分布式数据库
  1. DROP DATABASE foo_db;