Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
MySQL provides string types for a variety of purposes. Character strings are used to store text based strings. Binary strings store non-text based data. Fixed length strings are padded and always use the same amount of storage. Variable length strings use less storage when the strings are shorter, and large object storage is used for storing documents and media files. Character strings come in two varieties. The CHAR string is a fixed length string.
The parameters used to define the length of the string. For example, if you specify a length of 5, the string will alway be 5 characters in length. If you put fewer than 5 characters in the string, it will add spaces at the end of the string in order to pad it out to 5 characters, and when you retrieve the string from the table, any padded spaces are removed first. The VARCHAR string is variable in length. The parameter is used to limit the length of the string. For example, if you specify a length of 25, the string will have up to 25 characters, plus the 1 or 2 byte length value.
So if you put ten characters in the string, it will use 11 bytes of storage. So in practical terms you'll usually used fixed length CHAR strings for items of predictable size like postal codes or fixed size abbreviations, and VARCHAR for variable length strings with a reasonable maximum size like names, titles, and moderate sized units of writing. Binary strings work exactly like character strings except they have no character set and they use binary collation. The BINARY type works just like the CHAR type, except that instead of space characters of binary columns padded with zeroes.
And just like the CHAR type those zeroes are stripped when the data is read from the table. VARBINARY works just like VARCHAR, but with no character set, and with binary collation. Large object storage is stored separately from the table row, so the size of these columns does not count against the hard limit on the size of the row. BLOB objects are binary large objects, like binary strings, they don't have any character set and use binary collation. Text objects are just like blobs, but they do use a character set and coalition.
This table shows the different sizes and storage requirements of the different large objects. For most purposes I use BLOB, TEXT or LONGBLOB or LONGTEXT. TINYBLOB is small enough that I'll normally use a VARCHAR or VARBINARY instead. The difference in overhead between medium and long versions is negligible, so I'll generally just use the long version if the 64k version isn't big enough. MySQL provides a good set of string types that should suit most every need. The official list of string types also includes a couple of the special types that I'll deal with separately later in this chapter.
Get unlimited access to all courses for just $25/month.Become a member
82 Video lessons · 98181 Viewers
61 Video lessons · 85482 Viewers
71 Video lessons · 69439 Viewers
56 Video lessons · 101790 Viewers
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.
Your file was successfully uploaded.