1、建立分割槽表
create table `表名稱` (
`id` char(32) not null comment '12位的imei',
`ts` bigint(20) not null comment '報文解析出來的時間戳',
`create_time` bigint(20) not null comment '存入資料庫時間戳',
primary key (`id`,`ts`)
) engine=innodb default charset=utf8mb4 collate=utf8mb4_bin comment=''
partition by range columns(ts) (
partition `ts_2021_03_01` values less than (1614614400000),
partition `ts_2021_03_02` values less than (1614700800000),
partition `ts_2021_03_03` values less than (1614787200000)
)
2、檢視當前分割槽是否存在
select *
from information_schema.partitions
where table_schema='資料庫名稱'
and table_name='表名稱'
and partition_name='ts_2021_03_01'
3、上述查詢有結果則說明有分割槽,無結果則說明無分割槽,需要建分割槽
alter table `表名稱` add partition (partition ts_2021_03_04 values less than (unix_timestamp('2021-03-05 00:00:00')*1000));
Mysql資料庫自動寫入建立時間以及更新時間
create time timestamp not null default current timestamp comment 建立時間 update time timestamp not null default 0000 00 00 00 00 00 on update current tim...
sqlalchemy建立資料庫自動對映
coding utf 8 from datetime import datetime from sqlalchemy.ext.automap import automap base from sqlalchemy.orm import sessionmaker from sqlalchemy imp...
MySQL自動增刪分割槽 資料庫實現方案
基於資料儲存過程和事件實現 delimiter use sbtest drop procedure if exists create drop partition test1 create definer rim procedure create drop partition test1 begin...