色婷婷狠狠18禁久久YY,CHINESE性内射高清国产,国产女人18毛片水真多1,国产AV在线观看

mysql增加表分區的語句出錯

錢浩然2年前10瀏覽0評論

在MySQL數據庫中,分區表可以大大提高查詢效率和數據管理能力。在使用過程中,很多人會遇到增加表分區的語句出錯的問題。下面是一個例子。

ALTER TABLE `users` PARTITION BY RANGE(year_month) (
PARTITION p201701 VALUES LESS THAN (201702),
PARTITION p201702 VALUES LESS THAN (201703),
PARTITION p201703 VALUES LESS THAN (201704),
PARTITION p201704 VALUES LESS THAN (201705),
PARTITION p201705 VALUES LESS THAN (201706),
PARTITION p201706 VALUES LESS THAN (201707),
PARTITION p201707 VALUES LESS THAN (201708),
PARTITION p201708 VALUES LESS THAN (201709),
PARTITION p201709 VALUES LESS THAN (201710),
PARTITION p201710 VALUES LESS THAN (201711),
PARTITION p201711 VALUES LESS THAN (201712),
PARTITION p201712 VALUES LESS THAN (201801),
PARTITION p201801 VALUES LESS THAN (201802),
PARTITION p201802 VALUES LESS THAN (201803),
PARTITION p201803 VALUES LESS THAN (201804),
PARTITION p201804 VALUES LESS THAN (201805),
PARTITION p201805 VALUES LESS THAN (201806),
PARTITION p201806 VALUES LESS THAN (201807),
PARTITION p201807 VALUES LESS THAN (MAXVALUE)
);

以上代碼是要將名為“users”的表按照year_month字段進行分區,分成18個分區,其中17個分區對應2017年1月至2018年7月,最后一個分區是未來的數據。但是執行后的錯誤信息卻是:

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'VALUES LESS THAN (201702),
PARTITION p201702 VALUES LESS THAN (201703),
...

經過一番排查,發現是VALUES LESS THAN關鍵字位置的問題,修改后如下:

ALTER TABLE `users` PARTITION BY RANGE(year_month) (
PARTITION p201701 VALUES LESS THAN (201702),
PARTITION p201702 VALUES LESS THAN (201703),
PARTITION p201703 VALUES LESS THAN (201704),
PARTITION p201704 VALUES LESS THAN (201705),
PARTITION p201705 VALUES LESS THAN (201706),
PARTITION p201706 VALUES LESS THAN (201707),
PARTITION p201707 VALUES LESS THAN (201708),
PARTITION p201708 VALUES LESS THAN (201709),
PARTITION p201709 VALUES LESS THAN (201710),
PARTITION p201710 VALUES LESS THAN (201711),
PARTITION p201711 VALUES LESS THAN (201712),
PARTITION p201712 VALUES LESS THAN (201801),
PARTITION p201801 VALUES LESS THAN (201802),
PARTITION p201802 VALUES LESS THAN (201803),
PARTITION p201803 VALUES LESS THAN (201804),
PARTITION p201804 VALUES LESS THAN (201805),
PARTITION p201805 VALUES LESS THAN (201806),
PARTITION p201806 VALUES LESS THAN (201807),
PARTITION p201807 VALUES LESS THAN MAXVALUE
);

修改后,VALUES LESS THAN關鍵字成功放置在了正確的位置上。需要注意的是,在使用分區表時,一定要遵守MySQL數據庫的語法規則,否則會產生一系列的錯誤和問題。