Ich muss jeden Tag meine Tabelle partitionieren basierend auf UTC-Zeitstempel, erhalte ich Fehler als Fatal error: A PRIMARY KEY must include all columns in the table's partitioning function
MySQL - Primärschlüssel für die Partition benötigt
ich auf diese Weise tue, Spalte id
ist INT PRIMARY KEY-Spalte date
ist INT Speicherung UTC-Zeitstempel
Meine Tabellenstruktur DESCRIBE stats;
Field Type Null Key Default Extra
id int(11) NO PRI NULL auto_increment
date int(11) YES NULL
.
.
.
.
Tabellenstruktur erstellen SHOW CREATE TABLE stats
CREATE TABLE `stats` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`date` int(11) DEFAULT NULL,
.
.
.
.
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=371 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
I Skript über php
$today = strtotime("today midnight");
$partition = date('d_m_y',$today);
ALTER TABLE `stats`
PARTITION BY RANGE (date) (
PARTITION p_$partition VALUES LESS THAN ($today)
)
Ich habe versucht, dies auszuführen, aber Syntaxfehler
ALTER TABLE `stats`
UNIQUE KEY (`id`)
PARTITION BY RANGE (date) (
PARTITION p_$partition VALUES LESS THAN ($today)
)
ALTER TABLE `stats`
PRIMARY KEY (`id`)
PARTITION BY RANGE (date) (
PARTITION p_$partition VALUES LESS THAN ($today)
)
ALTER TABLE `stats`
PRIMARY KEY (`id`,`date`)
PARTITION BY RANGE (date) (
PARTITION p_$partition VALUES LESS THAN ($today)
)
auch versucht, mit HASH
aber gleichen Fehler A PRIMARY KEY must include all columns in the table's partitioning function in
ALTER TABLE stats
PARTITION BY HASH(date)
PARTITIONS 1
auch versucht, dies immer Weg aber bekam Fehler Fatal error: Partition management on a not partitioned table is not possible
ALTER TABLE `stats`
ADD PARTITION (
PARTITION p_$partition VALUES LESS THAN ($today)
)
Bitte sehen und deuten darauf hin, jede mögliche Art und Weise, dies zu tun.
Dank
Sie mischen PHP und SQL-Befehle. Wie führen Sie die SQL-Befehle aus? – Shadow
@Shadow mit PHP-Skript –
Mögliches Duplikat von [Ein Primär muss alle Spalten in der Partitionierungsortfehler der Tabelle enthalten?] (Http://stackoverflow.com/questions/11896067/a-primary-must-include-all-columns- in-the-tables-partitioning-location-error) – regulus