ADDING PARTITIONING MYSQL I'm using MySQL 5.7.17 and I have this table :

CREATE TABLE `posicaorastreadores` (
`Id` CHAR(36) COLLATE utf8_bin NOT NULL DEFAULT '',
`ComandoInicialString` VARCHAR(1024) COLLATE utf8_general_ci NOT NULL,
`Serial` BIGINT(20) NOT NULL,
`DataEnvio` DATETIME NOT NULL,
`DataGps` DATETIME NOT NULL,
`Latitude` DOUBLE NOT NULL,
`Longitude` DOUBLE NOT NULL,
`Velocidade` DOUBLE NOT NULL,
`TensaoBateriaPrincipal` DOUBLE NOT NULL,
`TensaoBateriaBackup` DOUBLE NOT NULL,
`DataInclusao` DATETIME NOT NULL,
`DataAlteracao` DATETIME NOT NULL,
`Ativado` TINYINT(1) NOT NULL,
`EnderecoArmazenado` TINYINT(4) NOT NULL DEFAULT 0,
`ModeloRastreador` INTEGER(11) NOT NULL,
PRIMARY KEY USING BTREE (`Id`),
KEY `enderecoArmazenado_idx` USING BTREE (`EnderecoArmazenado`),
KEY `serial_idx` USING BTREE (`Serial`),
KEY `datagps_idx` USING BTREE (`DataGps`),
KEY `ativado_idx` USING BTREE (`Ativado`),
KEY `ModeloRastreador_idx` USING BTREE (`ModeloRastreador`),
KEY `posicaorastreadores_idx1` USING BTREE (`ComandoInicialString`),
KEY `posicaorastreadores_idx2` USING BTREE (`DataEnvio`),
KEY `posicaorastreadores_idx3` USING BTREE (`Ativado`, `Serial`, `DataGps`)
) ENGINE=InnoDB
ROW_FORMAT=DYNAMIC CHARACTER SET 'utf8' COLLATE 'utf8_general_ci'
;


I need to use partitioning. 

I'm try to use with this command:

ALTER TABLE posicaorastreadores PARTITION BY HASH( DAYOFMONTH(DataGps) )
PARTITIONS 31; 


I'm receiving this error:


  A PRIMARY KEY must include all columns in the table's partitioning function
Inorder to get rid of the error you have got, you may follow below command.

    CREATE TABLE posicaorastreadores (  Id CHAR(36) COLLATE utf8_bin NOT 
NULL DEFAULT '',  ComandoInicialString VARCHAR(1024) COLLATE 
utf8_general_ci NOT NULL,  Serial BIGINT(20) NOT NULL,  DataEnvio DATETIME 
NOT NULL,  DataGps DATETIME NOT NULL,  Latitude DOUBLE NOT NULL,  Longitude 
DOUBLE NOT NULL,  Velocidade DOUBLE NOT NULL,  TensaoBateriaPrincipal 
DOUBLE NOT NULL,  TensaoBateriaBackup DOUBLE NOT NULL,  DataInclusao 
DATETIME NOT NULL,  DataAlteracao DATETIME NOT NULL,  Ativado TINYINT(1) 
NOT NULL,  EnderecoArmazenado TINYINT(4) NOT NULL DEFAULT 0,  
ModeloRastreador INTEGER(11) NOT NULL,  PRIMARY KEY USING BTREE 
(Id,DataGps),  KEY enderecoArmazenado_idx USING BTREE (EnderecoArmazenado),  
KEY serial_idx USING BTREE (Serial),  KEY datagps_idx USING BTREE 
(DataGps),  KEY ativado_idx USING BTREE (Ativado),  KEY 
ModeloRastreador_idx USING BTREE (ModeloRastreador),  KEY 
posicaorastreadores_idx1 USING BTREE (ComandoInicialString),  KEY 
posicaorastreadores_idx2 USING BTREE (DataEnvio),  KEY 
posicaorastreadores_idx3 USING BTREE (Ativado, Serial, DataGps)  ) 
ENGINE=InnoDB  ROW_FORMAT=DYNAMIC CHARACTER SET 'utf8' COLLATE 
'utf8_general_ci';


And then issue


  ALTER TABLE posicaorastreadores PARTITION BY HASH(
  DAYOFMONTH(DataGps) ) PARTITIONS 31;


You should add pk and partition key to be PK for the table.

PRIMARY KEY USING BTREE (Id,DataGps)


But looking at your table definition you have secondary indexes almost on all. You might want to verify on performance of all your selects. Or tune them inorder to add the partition name or partition key as a mandate clause in where clause. So its better you take perf against selects and updates you use and then think whether is it feasible to go for partitioning or archiving the table. 

Also if you are anyway going for partition, you need to define the partition in such a way older partition can be removed. So I would suggest to go for 


  PARTITION BY RANGE ( DAYOFMONTH(DataGps) ) ;


And define range each partitions.