Best Mysql Type to count accesses

1

I have a database containing PDF files, but I'm trying to count how many views this file had. The accounting structure is ready because it was done in PHP / Mysql, but I have a question. I usually put Type Varchar (255), but for this type is it ideal to do this count? With each access, I will use the UPDATE.

    
asked by anonymous 22.03.2018 / 15:20

1 answer

4

Count is numeric, and are integer and positive values.

The appropriate type for this, therefore, is INTEGER UNSIGNED (integer WITHOUT sign). In this family, we have these possibilities:

TIPO        BYTES   SIGNED                        UNSIGNED
=========== ======= ============================= =====================
TINYINT     1       de -128 a 127                 de 0 a 255
SMALLINT    2       de -32768 a 32767             de 0 a 65535
MEDIUMINT   3       de -8388608 a 8388607         de 0 a 16777215
INT         4       de -2147483648 a 2147483647   de 0 a 4294967295
BIGINT      8       de -2^63 a 2^63-1             de 0 a 2^64-1

Choose the type that best suits your case by predicting the maximum number you want to store.

More details in the manual:

  

link

    
22.03.2018 / 15:53