Global Header
3 Mins Read

MySQL Variable Types

Home Blog General MySQL Variable Types
Things to Keep in Mind When Picking a WordPress Theme

Summarize this blog post with:

MySQL, a popular relational database management system, uses various data types to define the kind of value a column can hold. Understanding MySQL variable types is critical for effective database design and data storage optimization.

In a MySQL database, there are three (3) main data types: text, numbers, and dates/times. When you design your database, you must select the appropriate type since this determines the data you can store in that column. Using the most appropriate type can also increase the database’s overall performance.

MySQL Variable Types

Text Types

CHAR( ) A fixed section from 0 to 300 characters long.
VARCHAR( ) A variable section from 0 to 300 characters long.
TINYTEXT A string with a maximum length of 300 characters.
TEXT A string with a maximum length of 65535 characters.
BLOB A string with a maximum length of 65535 characters.
MEDIUMTEXT  A string with a maximum length of 16777215 characters.
MEDIUMBLOB  A string with a maximum length of 16777215 characters.
LONGTEXT A string with a maximum length of 4294967295 characters.
LONGBLOB A string with a maximum length of 4294967295 characters.

The ( ) brackets allow you to specify the maximum  number of characters that can be used in the column.

BLOB stands for Binary Large Object, and can be used to store non-text information that is encoded into text.

Number Types

TINYINT ( ) -128 to 127 normal 0 to 255 UNSIGNED
SMALLINT( ) -32768 to 32767 normal 0 to 65535 UNSIGNED
MEDIUMINT( )     -8388608 to 8388607 normal 0 to 16777215 UNSIGNED
INT( ) -2147483648 to 2147483647 normal 0 to 4294967295 UNSIGNED
BIGINT( ) -9223372036854775808 to 9223372036854775807 normal 0 to 18446744073709551615 UNSIGNED
FLOAT A small number with a floating decimal point.
DOUBLE( , ) A large number with a floating decimal point.
DECIMAL( , ) A DOUBLE stored as a string, allowing for a fixed decimal point.

By default, the integer types will allow a range between negative and positive numbers, as indicated in the table above. You can use the UNSIGNED commend, which will instead only allow positive numbers, which start at 0 and count up.

Date/Time Types

DATE YYYY-MM-DD
DATETIME YYYY-MM-DD HH:MM:SS
TIMESTAMP  YYYYMMDDHHMMSS
TIME HH:MM:SS
YEAR YYYY

Date/Time fields will only accept a valid date or time.

Summary

Understanding MySQL variable types is essential for database design and management; by carefully selecting the appropriate data type – text, numbers, or dates/times – developers can ensure that their databases are optimized for storage and performance. Text types offer a range of options from fixed to variable lengths, accommodating different needs for storing text data. Number types provide precise control over the range of values, with the option to use unsigned for positive numbers only. Date/time types are crucial for recording temporal data accurately. Overall, effective use of these data types in MySQL can significantly enhance the functionality and efficiency of a database, making it a critical skill for developers and database administrators alike.

  • I am Mili Shah, a content writer at Bluehost with 5+ years of experience in writing technical content, ranging from web blogs to case studies. When not writing, you can find me lost in the wizarding world of Harry Potter.

Learn more about Bluehost Editorial Guidelines
View All

Write A Comment

Your email address will not be published. Required fields are marked *

Longest running WordPress.org recommended host.

Get Up to 61% off on hosting for WordPress Websites and Stores.

Table of Contents