7

If I want to store a port number in MySQL, what is the most efficient way (minimizing wasted space) to do so? Is it INT(5) or INT(3)?

I'm looking here and I think the answer is INT(3) (or perhaps MEDIUMINT).

2 Answers 2

7

Port number is an unsinged 16-bit integer. That means the highest value can be 65535. So you can use SMALLINT.

1
  • 3
    Yes it has to be UNSIGNED SMALLINT. The storage size would be the same but you would have only a range from -32768 to 32767...
    – Alex Vogt
    Dec 4, 2013 at 15:46
7

If you want to store the values as compactly as possible, the choice would be SMALLINT UNSIGNED which takes 2 bytes of storage.

See the manual for details.

Also FYI INT(5) and INT(3) both use 4 bytes of storage. The (5) and (3) are only used for display, not for storage.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.