#1
  1. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Location
    On planet earth
    Posts
    105
    Rep Power
    11

    MySQL datatypes question


    I am making my own project which would entail in having loads of text, which datatypes should I use for the MySQL database? VARCHAR or MEDIUMTEXT? I don't think I will be using the LONGTEXT as it is too much for what I am creating the database for. The limit is for 2000 characters to be stored in the database
    Last edited by cssbonding; September 9th, 2013 at 10:35 AM.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Mar 2006
    Posts
    2,484
    Rep Power
    1752
    Depending on what use you'd wish to make of the data I'd be inclined to go for VARCHAR.
    The moon on the one hand, the dawn on the other:
    The moon is my sister, the dawn is my brother.
    The moon on my left and the dawn on my right.
    My brother, good morning: my sister, good night.
    -- Hilaire Belloc
  4. #3
  5. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Location
    On planet earth
    Posts
    105
    Rep Power
    11
    Originally Posted by SimonJM
    Depending on what use you'd wish to make of the data I'd be inclined to go for VARCHAR.
    So I should put VARCHAR(2000) in the table structure?

    I've just read that if it goes about 255 characters (the text, which it evidently will above), it will be L + 2 or more bytes stored?
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Dec 2004
    Posts
    3,031
    Rep Power
    377
    unless i am wrong, varchar(255) is what the max is so you can store 255 chars as you rightly point out.

    i think medium text is fine but go for the "var char version" i.e. you have char (fixed length) and then you have varchar. there is a "medium text" version for either so go for variable length type! (lol if that made sense)
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Mar 2006
    Posts
    2,484
    Rep Power
    1752
    From, around, version 5 the maximum for VARCHAR was extended to 64K.

    I believe you are right, in the VARCHAR is stored as length of data + actual data, so a slight overhead. I'd probably go for a slightly higher number, just in case (say 2,500?).

    Comments on this post

    • cssbonding agrees : thanks
    The moon on the one hand, the dawn on the other:
    The moon is my sister, the dawn is my brother.
    The moon on my left and the dawn on my right.
    My brother, good morning: my sister, good night.
    -- Hilaire Belloc

IMN logo majestic logo threadwatch logo seochat tools logo