TechBeamersTechBeamers
  • Learn ProgrammingLearn Programming
    • Python Programming
      • Python Basic
      • Python OOP
      • Python Pandas
      • Python PIP
      • Python Advanced
      • Python Selenium
    • Python Examples
    • Selenium Tutorials
      • Selenium with Java
      • Selenium with Python
    • Software Testing Tutorials
    • Java Programming
      • Java Basic
      • Java Flow Control
      • Java OOP
    • C Programming
    • Linux Commands
    • MySQL Commands
    • Agile in Software
    • AngularJS Guides
    • Android Tutorials
  • Interview PrepInterview Prep
    • SQL Interview Questions
    • Testing Interview Q&A
    • Python Interview Q&A
    • Selenium Interview Q&A
    • C Sharp Interview Q&A
    • PHP Interview Questions
    • Java Interview Questions
    • Web Development Q&A
  • Self AssessmentSelf Assessment
    • Python Test
    • Java Online Test
    • Selenium Quiz
    • Testing Quiz
    • HTML CSS Quiz
    • Shell Script Test
    • C/C++ Coding Test
Search
  • Python Multiline String
  • Python Multiline Comment
  • Python Iterate String
  • Python Dictionary
  • Python Lists
  • Python List Contains
  • Page Object Model
  • TestNG Annotations
  • Python Function Quiz
  • Python String Quiz
  • Python OOP Test
  • Java Spring Test
  • Java Collection Quiz
  • JavaScript Skill Test
  • Selenium Skill Test
  • Selenium Python Quiz
  • Shell Scripting Test
  • Latest Python Q&A
  • CSharp Coding Q&A
  • SQL Query Question
  • Top Selenium Q&A
  • Top QA Questions
  • Latest Testing Q&A
  • REST API Questions
  • Linux Interview Q&A
  • Shell Script Questions
© 2024 TechBeamers. All Rights Reserved.
Reading: MySQL Data Types Explained
Font ResizerAa
TechBeamersTechBeamers
Font ResizerAa
  • Python
  • SQL
  • C
  • Java
  • Testing
  • Selenium
  • Agile Concepts Simplified
  • Linux
  • MySQL
  • Python Quizzes
  • Java Quiz
  • Testing Quiz
  • Shell Script Quiz
  • WebDev Interview
  • Python Basic
  • Python Examples
  • Python Advanced
  • Python OOP
  • Python Selenium
  • General Tech
Search
  • Programming Tutorials
    • Python Tutorial
    • Python Examples
    • Java Tutorial
    • C Tutorial
    • MySQL Tutorial
    • Selenium Tutorial
    • Testing Tutorial
  • Top Interview Q&A
    • SQL Interview
    • Web Dev Interview
  • Best Coding Quiz
    • Python Quizzes
    • Java Quiz
    • Testing Quiz
    • ShellScript Quiz
Follow US
© 2024 TechBeamers. All Rights Reserved.
MySQL Tutorial

MySQL Data Types Explained

Last updated: May 22, 2023 12:52 pm
By Meenakshi Agarwal
Share
9 Min Read
MySQL Data Types Explained with Examples
MySQL Data Types Explained with Examples
SHARE

This tutorial explains all MySQL data types, their characteristics, and min, max as well as possible default values. We’ll describe their usages so that you can use them efficiently for creating schemas and tables.

Contents
MySQL numeric data typesBooleanStringDate-Time TypesMySQL spatial data typesJSON data type

A MySQL table can have one or more fields with specific data types such as a string or date. However, there are more available in MySQL to ease up your job of collecting and storing data.

It is also crucial that you understand which data type should you use and when. Here are some standard goals that define them what do they represent:

1. The data, it is going to hold.
2. The size, it requires that can be static or variable.
3. Is the value of a kind indexable or not?
4. Does this type allow comparison?

MySQL Data Types: A Quick Overview

We can broadly subdivide them into the following types.

  • Numeric
  • Boolean
  • String
  • Date-time
  • Spatial
  • Json

mYsql dATA tYPES eXPLAINED

MySQL numeric data types

MySQL provides all usual SQL numeric types that contain: Number data types such as integer, fixed-point, and float.

Moreover, it also supports the BIT data type that can accept bit values. A numeric type can either be signed or unsigned. But the BIT type is a combination of 0s and 1s.

The following is the summary of different numeric types available in MySQL:

INT: A standard integer value that can be +ve and -ve. Its range is from -2147483648 to 2147483647. However, an unsigned int ranges from 0 to 4294967295. It allows width up to 11th place.

TINYINT: A non-regular tiny integer with a range from -128 to 127. It can go up to 255 for +ve only values. It allows width up to four places.

SMALLINT: Another short integer that has a range from -32768 to 32767. It can go up to 65535 for +ve only values. It allows width up to five digits.

MEDIUMINT: This int type has a range from -8388608 to 8388607. It can go up to 16777215 for +ve only values. It allows width up to nine digits.

BIGINT: The largest integer that ranges from -9223372036854775808 to 9223372036854775807. It goes up to 18446744073709551615 for +ve only values. It allows width up to twenty digits.

FLOAT − It is a single-precision decimal number. By default, it allows two decimal places and can hold up to 10 digits. However, you can define a precision of 24 digits.

DOUBLE: It is a double-precision float number. By default, it allows four decimal places and can hold up to 16 digits. However, you can define precision as big as 53.

DECIMAL: It is a fixed-point number, which means that each digit corresponds to one byte.

Boolean

There is not a dedicated type in MySQL for BOOLEAN values. However, it provides the TINYINT to define a boolean. It is the smallest integer type.

Hence, you can also use words like BOOLEAN or BOOL rather than mentioning the type as TINYINT.

String

The MySQL string data type can accept a plain text or binary data (images or data files). You can compare string values, and search substrings using pattern matching. It provides different ways to do that such as LIKE operator, Regex, and simple text lookup. Here is the summary of MySQL string data types:

CHAR: The regular fixed-size string which can hold up to 255 characters. It is right-padded with spaces, and the default size is 1.

VARCHAR: Another regular string type which is variable in length. It can hold up to 255 characters. You should provide the size while specifying a VARCHAR type.

BLOB: BLOB is an acronym that means Binary Large Objects. It allows storage for large-sized binary data, such as pictures or other kinds of files. You can store a maximum of 65535 characters.

TEXT: TEXT field can also take sizable data. While sorting or comparing TEXT type data, the case doesn’t matter. However, BLOB data is case sensitive for these operations. Also, none of the BLOB or TEXT requires to specify the size for creating fields.

TINYBLOB/TINYTEXT: Both of these can accept a maximum of 255 characters as input. And none of the two needs the size with their types.

MEDIUMBLOB/MEDIUMTEXT: Another enhanced version of BLOB/TEXT which can take up to 16777215 characters. Rest of its features are the same as its predecessors.

LONGBLOB/LONGTEXT: It is the largest of all BLOB types with a maximum capacity of 4294967295 characters.

ENUM: It is a list type field which can store multiple elements. It can have NULL values. For example, you can define an ENUM as ENUM (‘X’, ‘Y’, ‘Z’).

SET: This field can take zero or more SET elements.

Date-Time Types

You can have the following MySQL date-time data types:

DATE: It accepts the values in YYYY-MM-DD format. It starts with 1000-01-01 and can go up to 9999-12-31. A simple example is where July 27th, 2019 would appear as 2019-07-27.

DATETIME: It is the combination of a date and time. Its storage format is YYYY-MM-DD HH:MM: SS. It starts with 1000-01-01 00:00:00 and can go up to 9999-12-31 23:59:59. A simple example is where 4:45 in the evening on July 27th, 2019 would appear as 2019-07-27 16:45:00.

TIMESTAMP: It is similar to TIMESTAMP and contains both time and date. It doesn’t include the hyphens separator. A simple example is where 4:45 in the evening on July 27th, 2019 would appear as 20190727164500.

TIME: It is the simplest of the date data types which allow only time as HH:MM: SS.

YEAR: Another date type which takes a year in a 2/4 digit format. The year value goes from (1970 to 2069) or (70 to 69). However, when the length is 4 (default), then it goes from 1901 to 2155.

MySQL spatial data types

MySQL comes with many spatial data types that include some geometrical as well as geographical values.

However, here is the summary of Spatial data types:

GEOMETRY: A spatial value of any kind

POINT: A pair of coordinates (X, Y)

LINESTRING: A linear curve with one or more point

POLYGON: A polygon field

GEOMETRYCOLLECTION: A collection of POINT and LINESTRING values

MULTILINESTRING: A group of many linestrings

MULTIPOINT: A collection of POINT type values

MULTIPOLYGON: A set of POLYGON type values

JSON data type

JSON is a popular acronym for JavaScript Object Notation. We often use this type of data for transferring info between a server and web application.

MySQL supports it since version 5.7.8. It allows you to store and handle JSON data in a better way. It also provides automatic checking of the JSON format.

We hope that after wrapping up this tutorial, you should feel comfortable in using the MySQL TIMESTAMP. However, you may practice more with examples to gain confidence.

Also, to learn SQL from scratch to depth, do read our step by step MySQL tutorial.

You Might Also Like

MySQL vs MongoDB Comparison

Concatenate Strings in an SQL Query With Examples

The Difference between UPSERT & Insert

SQL Programming Test in 2024

SQL Table Creation: The Missing Manual

Meenakshi Agarwal Avatar
By Meenakshi Agarwal
Follow:
Hi, I'm Meenakshi Agarwal. I have a Bachelor's degree in Computer Science and a Master's degree in Computer Applications. After spending over a decade in large MNCs, I gained extensive experience in programming, coding, software development, testing, and automation. Now, I share my knowledge through tutorials, quizzes, and interview questions on Python, Java, Selenium, SQL, and C# on my blog, TechBeamers.com.
Previous Article MySQL TIMESTAMP with Simple Examples MySQL TIMESTAMP with Examples
Next Article MySQL ORDER BY with ASC DESC Examples MySQL ORDER BY with Simple Examples

Popular Tutorials

SQL Interview Questions List
50 SQL Practice Questions for Good Results in Interview
SQL Interview Nov 01, 2016
Demo Websites You Need to Practice Selenium
7 Sites to Practice Selenium for Free in 2024
Selenium Tutorial Feb 08, 2016
SQL Exercises with Sample Table and Demo Data
SQL Exercises – Complex Queries
SQL Interview May 10, 2020
Java Coding Questions for Software Testers
15 Java Coding Questions for Testers
Selenium Tutorial Jun 17, 2016
30 Quick Python Programming Questions On List, Tuple & Dictionary
30 Python Programming Questions On List, Tuple, and Dictionary
Python Basic Python Tutorials Oct 07, 2016
//
Our tutorials are written by real people who’ve put in the time to research and test thoroughly. Whether you’re a beginner or a pro, our tutorials will guide you through everything you need to learn a programming language.

Top Coding Tips

  • PYTHON TIPS
  • PANDAS TIPSNew
  • DATA ANALYSIS TIPS
  • SELENIUM TIPS
  • C CODING TIPS
  • GDB DEBUG TIPS
  • SQL TIPS & TRICKS

Top Tutorials

  • PYTHON TUTORIAL FOR BEGINNERS
  • SELENIUM WEBDRIVER TUTORIAL
  • SELENIUM PYTHON TUTORIAL
  • SELENIUM DEMO WEBSITESHot
  • TESTNG TUTORIALS FOR BEGINNERS
  • PYTHON MULTITHREADING TUTORIAL
  • JAVA MULTITHREADING TUTORIAL

Sign Up for Our Newsletter

Subscribe to our newsletter to get our newest articles instantly!

Loading
TechBeamersTechBeamers
Follow US
© 2024 TechBeamers. All Rights Reserved.
  • About
  • Contact
  • Disclaimer
  • Privacy Policy
  • Terms of Use
TechBeamers Newsletter - Subscribe for Latest Updates
Join Us!

Subscribe to our newsletter and never miss the latest tech tutorials, quizzes, and tips.

Loading
Zero spam, Unsubscribe at any time.
x