Mysql – difference in using INT(1) vs TINYINT(1) in MySQL

integerMySQLtypes

I'm under the assumption that INT(1) is the exact same thing as TINYINT(1) but I really have no idea. Whenever I've had values that can only be a single integer (e.g. a value 0-9), I've always just used INT(1) to say it's an integer and it will only be one character, which I assume means that it could only be a value 0 through 9 (please explain this to me if I'm wrong). I've always just ignored the other types of INT that you can cast the number as. I'm no MySQL savvy and tend to avoid the more complicated things you can do with it.

So my question, is there any difference between the various integer types INT, TINYINT, SMALLINT, MEDIUMINT, and BIGINT if you define a length of 1 for each type;? If not, should I use them anyways (I can see using them for more semantic meaning, TINYINT being more specific than just INT)? If so, could I easily (and/or should I) just go through my database and change all my INT(1) fields to TINYINT(1) fields?

Best Answer

Here you'll understand it in a better way!

tinyint: 1 byte, -128 to +127 / 0 to 255 (unsigned)
smallint: 2 bytes, -32,768 to +32,767 / 0 to 65,535 (unsigned)
mediumint: 3 bytes, -8,388,608 to 8,388,607 / 0 to 16,777,215 (unsigned)
int/integer: 4 bytes, -2,147,483,648 to +2,147,483,647 / 0 to 4,294,967,295 (unsigned)
bigint: 8 bytes, -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 / 0 to 18,446,744,073,709,551,615 (unsigned)