中文字幕av专区_日韩电影在线播放_精品国产精品久久一区免费式_av在线免费观看网站

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

MySQL中怎么實現表分區功能

發布時間:2021-08-04 16:52:52 來源:億速云 閱讀:152 作者:Leah 欄目:數據庫

今天就跟大家聊聊有關MySQL中怎么實現表分區功能,可能很多人都不太了解,為了讓大家更加了解,小編給大家總結了以下內容,希望大家根據這篇文章可以有所收獲。

 MySQL表分區功能基礎
  創建分區表
  CREATE TABLE `表名` (
  `EQUIPMENTID` char(17) NOT NULL,
  `ATTRIBUTEID` char(4) NOT NULL,
  `VALUE` varchar(20) NOT NULL,
  `COLLECTTIME` datetime NOT NULL
  )
  ENGINE=InnoDB (適用大部分引擎,可根據需要調整)
  DEFAULT CHARSET=gbk(編碼可根據需要修改)
  PARTITION BY RANGE (to_days(COLLECTTIME))
  (PARTITION pmin VALUES LESS THAN (to_days('2010-01-01')),
  PARTITION p201001 VALUES LESS THAN (to_days('2010-02-01')) ,
  PARTITION p201002 VALUES LESS THAN (to_days('2010-03-01')) ,
  PARTITION p201003 VALUES LESS THAN (to_days('2010-04-01')) ,
  PARTITION p201004 VALUES LESS THAN (to_days('2010-05-01')) ,
  PARTITION p201005 VALUES LESS THAN (to_days('2010-06-01')) ,
  PARTITION p201006 VALUES LESS THAN (to_days('2010-07-01')) ,
  PARTITION p201007 VALUES LESS THAN (to_days('2010-08-01')) ,
  PARTITION p201008 VALUES LESS THAN (to_days('2010-09-01')) ,
  PARTITION p201009 VALUES LESS THAN (to_days('2010-10-01')) ,
  PARTITION p201010 VALUES LESS THAN (to_days('2010-11-01')),
  PARTITION p201011 VALUES LESS THAN (to_days('2010-12-01')),
  PARTITION p201012 VALUES LESS THAN (to_days('2011-01-01')),
  PARTITION p201101 VALUES LESS THAN (to_days('2011-02-01')),
  PARTITION p201102 VALUES LESS THAN (to_days('2011-03-01')),
  PARTITION p201103 VALUES LESS THAN (to_days('2011-04-01')),
  PARTITION p201104 VALUES LESS THAN (to_days('2011-05-01')),
  PARTITION p201105 VALUES LESS THAN (to_days('2011-06-01')),
  PARTITION p201106 VALUES LESS THAN (to_days('2011-07-01')),
  PARTITION p201107 VALUES LESS THAN (to_days('2011-08-01')),
  PARTITION p201108 VALUES LESS THAN (to_days('2011-09-01')),
  PARTITION p201109 VALUES LESS THAN (to_days('2011-10-01')),
  PARTITION p201110 VALUES LESS THAN (to_days('2011-11-01')),
  PARTITION p201111 VALUES LESS THAN (to_days('2011-12-01')),
  PARTITION p201112 VALUES LESS THAN (to_days('2012-01-01')),
  PARTITION pmax VALUES LESS THAN MAXVALUE );
  為現有表創建分區
  alter table 表名
  PARTITION BY RANGE (to_days(COLLECTTIME))
  (PARTITION pmin VALUES LESS THAN (to_days('2010-01-01')),
  PARTITION p201001 VALUES LESS THAN (to_days('2010-02-01')) ,
  PARTITION p201002 VALUES LESS THAN (to_days('2010-03-01')) ,
  PARTITION p201003 VALUES LESS THAN (to_days('2010-04-01')) ,
  PARTITION p201004 VALUES LESS THAN (to_days('2010-05-01')) ,
  PARTITION p201005 VALUES LESS THAN (to_days('2010-06-01')) ,
  PARTITION p201006 VALUES LESS THAN (to_days('2010-07-01')) ,
  PARTITION p201007 VALUES LESS THAN (to_days('2010-08-01')) ,
  PARTITION p201008 VALUES LESS THAN (to_days('2010-09-01')) ,
  PARTITION p201009 VALUES LESS THAN (to_days('2010-10-01')) ,
  PARTITION p201010 VALUES LESS THAN (to_days('2010-11-01')),
  PARTITION p201011 VALUES LESS THAN (to_days('2010-12-01')),
  PARTITION p201012 VALUES LESS THAN (to_days('2011-01-01')),
  PARTITION p201101 VALUES LESS THAN (to_days('2011-02-01')),
  PARTITION p201102 VALUES LESS THAN (to_days('2011-03-01')),
  PARTITION p201103 VALUES LESS THAN (to_days('2011-04-01')),
  PARTITION p201104 VALUES LESS THAN (to_days('2011-05-01')),
  PARTITION p201105 VALUES LESS THAN (to_days('2011-06-01')),
  PARTITION p201106 VALUES LESS THAN (to_days('2011-07-01')),
  PARTITION p201107 VALUES LESS THAN (to_days('2011-08-01')),
  PARTITION p201108 VALUES LESS THAN (to_days('2011-09-01')),
  PARTITION p201109 VALUES LESS THAN (to_days('2011-10-01')),
  PARTITION p201110 VALUES LESS THAN (to_days('2011-11-01')),
  PARTITION p201111 VALUES LESS THAN (to_days('2011-12-01')),
  PARTITION p201112 VALUES LESS THAN (to_days('2012-01-01')),
  PARTITION pmax VALUES LESS THAN MAXVALUE );
  如果表中已有數據,分區時會自動進行分區存儲,不必擔心數據丟失或者手動分類數據.
  刪除表中的指定分區
  ALTER TABLE 表名 DROP PARTITION 分區名;
  追加表分區
  ALTER TABLE 表名 DROP PARTITION pmax;
  ALTER TABLE 表名
  ADD PARTITION (
  PARTITION p201201 VALUES LESS THAN (to_days('2012-2-1')),
  PARTITION pmax VALUES LESS THAN MAXVALUE);
  查看標分區信息
  SELECT
  partition_name part,
  partition_expression expr,
  partition_description descr,
  table_rows
  FROM
  INFORMATION_SCHEMA.partitions
  WHERE
  TABLE_SCHEMA = schema()
  AND TABLE_NAME='表名';
  查看查詢語句涉及分區信息
  explain partitions
  select … from 表名 where …;
  該操作只查看查詢語句相關的分區信息,不會返回查詢結果.

看完上述內容,你們對MySQL中怎么實現表分區功能有進一步的了解嗎?如果還想了解更多知識或者相關內容,請關注億速云行業資訊頻道,感謝大家的支持。

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

乳山市| 抚远县| 思茅市| 张家川| 治县。| 汶川县| 十堰市| 望江县| 集贤县| 那曲县| 浦江县| 深泽县| 铅山县| 沙雅县| 锡林浩特市| 易门县| 秦皇岛市| 济宁市| 凤台县| 郧西县| 溆浦县| 民丰县| 高雄市| 阿拉善右旗| 来安县| 东平县| 蚌埠市| 达拉特旗| 桦甸市| 寿阳县| 共和县| 大理市| 乐昌市| 南陵县| 邮箱| 年辖:市辖区| 仁布县| 乐安县| 白沙| 阳高县| 洛阳市|