MySQL INT(1) or INT(10)

In short, it really doesn’t matter.  After watching a MySQL web conference by Jay Pipes, I was gutted when I found out that they are actually exactly the same.  I know im not alone in thinking that it affected the size of the data field.  An unsigned int has the max value of 4294967295 no matter if its INT(1) or int(10) and will use 4 bytes of data.

So, what does the number in the brackets mean?  It pretty much comes down to display, its called the display-width.  The display width is a number from 1 to 255. You can set the display width if you want all of your integer values to “appear”.  If you enable zerofill on the row, the field will have a default value of 0 for int(1) and 0000000000 for int(10).

There are 5 main numeric data types, and you should choose each one on its own merits.   Based on the data you expect (or in some cases hope) to hold, you should use the correct data type.  If you dont ever expect to use a value of above 127 and below -128, you should use a tinyint.  This will only use 1 byte of data, which may not seem like much of a difference between the 4 used by an int, but as soon as you start to store more and more data, the effect on speed and space will be noticable.

Anyway, I thought I should share my new found knowledge of the display width with everyone, because it will save me thinking its optimising stuff changing from 10 to 5, haha.

17 Responses to “MySQL INT(1) or INT(10)”

  1. Roel says:

    Just what I was looking for. Thanks for the clear explanation!

  2. Jasper says:

    I never knew that! Every day’s a school day!

  3. tom3k says:

    brilliant!

    i was always under the assumption that this affected the data inside the column in some way!

    thank you kindly for the clear and precise description!

  4. thomas says:

    thanks for the information!
    haven’t knew it yet, but is pretty nice to know

  5. ayumilove says:

    thanks for the explanation!

  6. Kyle says:

    Cool post. Google’d what int(10) meant and found your post right away. Thanks for ur knowledge :)

  7. Jamal Olugosch says:

    I suspected as such, thanks for clearly defining it for me.

  8. Ronak says:

    Thanks, new thing for me as i was in wrong assumption about INT(4) and INT(10)

    Thanks buddy…!! :)

  9. ravichandran says:

    thanks for the display width info..

  10. kanya says:

    Many thanks for your clear explanation..

  11. Jstall says:

    Wow. I had no idea. I’ve been wasting my time doing that!!!! Thanks for the info. I’m thinking back now to all the time I wasted thinking about whether to make a field int(5) or int(6) etc. Now I know : – ).

  12. Tony says:

    I’ve spent literally HOURS searching the web for an explanation!!!

    Very nice and simple explanation. Many thanks for that!
    :o )

  13. C.Arumugam says:

    This is really a useful information . Thanks lot dude :)

  14. thommy says:

    Hey! Very thanks! This is the answer that i have search. :)

  15. Kan says:

    Great info. As some of them said – Clear, precise explanation. Found as the first result on Google when searched for ‘mysql int(1)’ .

  16. Ahmad Tamimi says:

    Thanks for good explanation and information sharing

  17. Jankoni says:

    I like great and simply explanation.Thanks for interesting post!


Leave a Reply