{"id":3875,"date":"2023-11-25T12:26:03","date_gmt":"2023-11-25T12:26:03","guid":{"rendered":"https:\/\/www.copahost.com\/blog\/?p=3875"},"modified":"2023-11-25T12:31:24","modified_gmt":"2023-11-25T12:31:24","slug":"mysql-data-types","status":"publish","type":"post","link":"https:\/\/www.copahost.com\/blog\/mysql-data-types\/","title":{"rendered":"What are MySQL data types?"},"content":{"rendered":"<figure class=\"wp-block-post-featured-image\"><img fetchpriority=\"high\" decoding=\"async\" width=\"1080\" height=\"1080\" src=\"https:\/\/www.copahost.com\/blog\/wp-content\/uploads\/2023\/11\/dados-do-mysql-ingles.png\" class=\"attachment-post-thumbnail size-post-thumbnail wp-post-image\" alt=\"mysql data types\" style=\"object-fit:cover;\" srcset=\"https:\/\/www.copahost.com\/blog\/wp-content\/uploads\/2023\/11\/dados-do-mysql-ingles.png 1080w, https:\/\/www.copahost.com\/blog\/wp-content\/uploads\/2023\/11\/dados-do-mysql-ingles-300x300.png 300w, https:\/\/www.copahost.com\/blog\/wp-content\/uploads\/2023\/11\/dados-do-mysql-ingles-1024x1024.png 1024w, https:\/\/www.copahost.com\/blog\/wp-content\/uploads\/2023\/11\/dados-do-mysql-ingles-150x150.png 150w, https:\/\/www.copahost.com\/blog\/wp-content\/uploads\/2023\/11\/dados-do-mysql-ingles-768x768.png 768w, https:\/\/www.copahost.com\/blog\/wp-content\/uploads\/2023\/11\/dados-do-mysql-ingles-50x50.png 50w\" sizes=\"(max-width: 1080px) 100vw, 1080px\" \/><\/figure>\n\n\n<p>MySQL, one of the leading relational database management systems, offers a variety of data types so that developers can store data of different types and formats.\u00a0Data management is fundamental to any information system, and\u00a0<strong>one of the most important aspects of data management is choosing the appropriate data type for each value stored in the database<\/strong>.\u00a0Additionally, having a clear understanding of data types can help you\u00a0<a href=\"https:\/\/www.copahost.com\/blog\/category\/linux-tutorials\/mysql\/\">write more efficient and scalable code<\/a>, and avoid common mistakes related to data management.<\/p>\n\n\n\n<p>In this article, we will explore the&nbsp;<strong>data types available in MySQL<\/strong>&nbsp;and discuss their specific characteristics and uses.&nbsp;In that vein, let&#8217;s start with an overview of numeric data types, followed by an analysis of&nbsp;<strong>character, datetime, binary, geometric, full-text, and Unicode data types<\/strong>.&nbsp;By understanding the different types of data available in&nbsp;MySQL, you can make informed decisions about how to store and manage data in your application.<\/p>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_69_1 ez-toc-wrap-center counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/www.copahost.com\/blog\/mysql-data-types\/#Numeric_data_types\" title=\"Numeric data types\">Numeric data types<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/www.copahost.com\/blog\/mysql-data-types\/#Character_data_types\" title=\"Character data types\">Character data types<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/www.copahost.com\/blog\/mysql-data-types\/#Full-text_data_types\" title=\"Full-text data types\">Full-text data types<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/www.copahost.com\/blog\/mysql-data-types\/#MySQL_Date_and_Time_Data_Types\" title=\"MySQL Date and Time Data Types\">MySQL Date and Time Data Types<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/www.copahost.com\/blog\/mysql-data-types\/#MySQL_binary_data_types\" title=\"MySQL binary data types\">MySQL binary data types<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/www.copahost.com\/blog\/mysql-data-types\/#Range_data_types\" title=\"Range data types\">Range data types<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/www.copahost.com\/blog\/mysql-data-types\/#MySQL_geometric_data_types\" title=\"MySQL geometric data types\">MySQL geometric data types<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/www.copahost.com\/blog\/mysql-data-types\/#Unicode_data_types\" title=\"Unicode data types\">Unicode data types<\/a><\/li><\/ul><\/nav><\/div>\n\n\n\n<div class=\"wp-block-image\">\n<figure class=\"alignleft size-full is-resized\"><img decoding=\"async\" width=\"740\" height=\"740\" src=\"https:\/\/www.copahost.com\/blog\/wp-content\/uploads\/2023\/11\/image-2.png\" alt=\"mysql data types\" class=\"wp-image-3885\" style=\"width:128px;height:auto\" srcset=\"https:\/\/www.copahost.com\/blog\/wp-content\/uploads\/2023\/11\/image-2.png 740w, https:\/\/www.copahost.com\/blog\/wp-content\/uploads\/2023\/11\/image-2-300x300.png 300w, https:\/\/www.copahost.com\/blog\/wp-content\/uploads\/2023\/11\/image-2-150x150.png 150w, https:\/\/www.copahost.com\/blog\/wp-content\/uploads\/2023\/11\/image-2-50x50.png 50w\" sizes=\"(max-width: 740px) 100vw, 740px\" \/><\/figure>\n<\/div>\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Numeric_data_types\"><\/span>Numeric data types<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>MySQL numeric data types are used to store numeric values \u200b\u200bwith different sizes and precisions.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>INT<\/strong>&nbsp;: The INT data type is used to store integer values.&nbsp;See the example:<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>INSERT INTO my_values \u200b\u200b(integer_value) VALUES (10);<\/code><\/pre>\n\n\n\n<ol class=\"wp-block-list\" start=\"2\">\n<li><strong>BIGINT<\/strong>&nbsp;: BIGINT data type is similar to INT type but can store larger integer values, suitable for storing large integer values \u200b\u200band in this sense, used in tables with many rows and columns.&nbsp;See the example:<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>INSERT INTO my_values \u200b\u200b(large_value) VALUES (9223372036854775808);<\/code><\/pre>\n\n\n\n<ol class=\"wp-block-list\" start=\"3\">\n<li><strong>SMALLINT<\/strong>&nbsp;: The SMALLINT data type is used to store smaller integer values \u200b\u200band is used in tables with limited values.&nbsp;See the example:<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>INSERT INTO my_values \u200b\u200b(small_value) VALUES (-32768);<\/code><\/pre>\n\n\n\n<ol class=\"wp-block-list\" start=\"4\">\n<li><strong>TINYINT<\/strong>&nbsp;: The TINYINT data type is similar to the SMALLINT type, but can store integer values \u200b\u200bin a range of -128 to 127. See example:<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>INSERT INTO my_values \u200b\u200b(very_small_value) VALUES (-128);<\/code><\/pre>\n\n\n\n<ol class=\"wp-block-list\" start=\"5\">\n<li><strong>DECIMAL<\/strong>&nbsp;: DECIMAL data type is used to store numeric values \u200b\u200bwith a specified precision, suitable for storing monetary and financial values.&nbsp;See the example:<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>INSERT INTO my_values \u200b\u200b(decimal_value) VALUES (123.45);<\/code><\/pre>\n\n\n\n<ol class=\"wp-block-list\" start=\"6\">\n<li><strong>FLOAT<\/strong>&nbsp;: FLOAT data type is used to store numeric values \u200b\u200bwith a specific precision.&nbsp;Thus, storing decimal number values \u200b\u200bof up to 6 digits.&nbsp;See the example:<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>INSERT INTO my_values \u200b\u200b(float_value) VALUES (3.1415926535897932385);<\/code><\/pre>\n\n\n\n<ol class=\"wp-block-list\" start=\"7\">\n<li><strong>DOUBLE<\/strong>&nbsp;: The DOUBLE data type is similar to the FLOAT type, but it can store numeric values \u200b\u200bwith a higher precision, up to 15-16 digits.&nbsp;This way, it stores decimal values, such as financial and scientific values.&nbsp;See the example:<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>INSERT INTO my_values \u200b\u200b(double_value) VALUES (3.14159265358979323846);<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Character_data_types\"><\/span>Character data types<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>MySQL&#8217;s character data types are used to store text and character data.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>CHAR<\/strong>&nbsp;: CHAR data type is used to store fixed text data with a specific length.&nbsp;In this sense, it is used when creating tables to store text values \u200b\u200bwith the same size in all columns.&nbsp;See the example that creates a table \u201cmy_values\u201d with a column \u201cname\u201d and stores texts of a maximum of 10 characters in length.<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>CREATE TABLE my_values \u200b\u200b(\n    name CHAR(10)\n);<\/code><\/pre>\n\n\n\n<ol class=\"wp-block-list\" start=\"2\">\n<li><strong>VARCHAR<\/strong>&nbsp;: The VARCHAR data type is similar to the CHAR type, but allows text values \u200b\u200bto be variable, with different lengths in each column.&nbsp;As such, it is used when creating tables to store text values \u200b\u200bwith variable lengths.&nbsp;See the example below that creates a \u201cmy_values\u201d table with an \u201cemail\u201d column that can store texts of up to 200 characters in length, being flexible in terms of the size of the data stored:<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>CREATE TABLE my_values \u200b\u200b(\n    email VARCHAR(200)\n);<\/code><\/pre>\n\n\n\n<ol class=\"wp-block-list\" start=\"3\">\n<li><strong>TEXT<\/strong>&nbsp;: The TEXT data type is used to store long and complex text data, with lengths ranging from 1 to 4 GB.&nbsp;Thus, it stores content-heavy text values, such as blog articles and documents.&nbsp;See the example:<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>INSERT INTO my_values \u200b\u200b(description) VALUES ('This is an example of a long text value');<\/code><\/pre>\n\n\n\n<ol class=\"wp-block-list\" start=\"4\">\n<li><strong>BLOB<\/strong>&nbsp;: The BLOB data type is used to store binary data, such as images, videos and document files.&nbsp;In this sense, it stores large values \u200b\u200band can store up to 65,535 bytes of data.&nbsp;Thus, see the example:<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>INSERT INTO my_values \u200b\u200b(image) VALUES (FILE('\/path\/to\/image.jpg'));<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Full-text_data_types\"><\/span>Full-text data types<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>FULLTEXT<\/strong>&nbsp;:<\/h4>\n\n\n\n<p>The FULLTEXT data type is used to store text data and perform full-text queries.&nbsp;Thus, it supports full-text queries across multiple fields and allows the use of collision and proximity operations to find more accurate results.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>CREATE TABLE books (\n  id INT PRIMARY KEY,\n  TEXT title,\n  author TEXT,\n  TEXT content,\n  KEY(content)(FULLTEXT)\n);\n\nINSERT INTO books (id, title, author, content) VALUES (1, 'Book 1', 'Author 1', 'Content 1, Content 2, Content 3');<\/code><\/pre>\n\n\n\n<p>In this example, the \u201ccontent\u201d column is of type TEXT and is indexed with FULLTEXT.&nbsp;Thus, this allows MySQL to perform full-text queries on all columns indexed with FULLTEXT.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"alignleft is-resized\"><img decoding=\"async\" src=\"https:\/\/www.homehost.com.br\/blog\/wp-content\/uploads\/2023\/11\/image-5.png\" alt=\"mysql data and time data types\" class=\"wp-image-11949\" style=\"width:77px;height:auto\"\/><\/figure>\n<\/div>\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"MySQL_Date_and_Time_Data_Types\"><\/span>MySQL Date and Time Data Types<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>In MySQL date and time data types are used to store date and time values.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>DATE<\/strong>&nbsp;: The DATE data type is used to store only the date without the time.&nbsp;Therefore, it is made up of 8 bytes and can store date values \u200b\u200bin the range of 1000 to 9999 for the year and 0 to 65535 for the day of the month.&nbsp;See the example:<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>INSERT INTO my_values \u200b\u200b(date) VALUES ('2022-03-14');<\/code><\/pre>\n\n\n\n<ol class=\"wp-block-list\" start=\"2\">\n<li><strong>TIME<\/strong>&nbsp;: The TIME data type is used to store only the time without the date.&nbsp;Thus, see the example:<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>INSERT INTO my_values \u200b\u200b(time) VALUES ('13:30:00');<\/code><\/pre>\n\n\n\n<ol class=\"wp-block-list\" start=\"3\">\n<li><strong>DATETIME<\/strong>&nbsp;: The DATETIME data type is used to store date and time values \u200b\u200btogether.&nbsp;See the example:<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>INSERT INTO my_values \u200b\u200b(date_time) VALUES ('2022-03-14 13:30:00');<\/code><\/pre>\n\n\n\n<ol class=\"wp-block-list\" start=\"4\">\n<li><strong>TIMESTAMP<\/strong>&nbsp;: The TIMESTAMP data type is similar to the DATETIME type, but includes precision to the second.&nbsp;See the example:<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>INSERT INTO my_values \u200b\u200b(date_time_seconds) VALUES ('2022-03-14 13:30:00');<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"MySQL_binary_data_types\"><\/span>MySQL binary data types<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Supports MySQL several binary data types, each of which has its own characteristics and uses.&nbsp;Here they are:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>BIT<\/strong>&nbsp;: The BIT data type is a simple binary type that can have a single value of 0 or 1. Thus, see example:<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>CREATE TABLE people (\n  id INT PRIMARY KEY,\n  BIT sex);\n\nINSERT INTO people (id, gender) VALUES (1, 1);<\/code><\/pre>\n\n\n\n<ol class=\"wp-block-list\" start=\"2\">\n<li><strong>BITMAP<\/strong>&nbsp;: The BITMAP data type is a more complex binary type that allows you to store multiple bit values \u200b\u200bin a single column.&nbsp;See the example:<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>CREATE TABLE people (\n  id INT PRIMARY KEY,\n  hobbies BITMAP);\n\nINSERT INTO people (id, hobbies) VALUES (1, 0b00100000);<\/code><\/pre>\n\n\n\n<ol class=\"wp-block-list\" start=\"3\">\n<li><strong>SET<\/strong>&nbsp;: The SET data type is a binary type that allows you to store multiple bit values \u200b\u200bin a single column.&nbsp;In this sense, SET is similar to BITMAP, but easier to use and offers better performance.&nbsp;See the example:<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>CREATE TABLE people (\n  id INT PRIMARY KEY,\n  hobbies SET);\n\nINSERT INTO people (id, hobbies) VALUES (1, 'reading, cinema');<\/code><\/pre>\n\n\n\n<ol class=\"wp-block-list\" start=\"4\">\n<li><strong>ENUM<\/strong>&nbsp;: The ENUM data type is a binary type that allows you to store a value from a predefined list of values.&nbsp;See the example:<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>CREATE TABLE colors (\n  id INT PRIMARY KEY,\n  color ENUM('green', 'blue', 'purple'));\n\nINSERT INTO colors (id, color) VALUES (1, 'green');<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Range_data_types\"><\/span>Range <code>data types<\/code><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>YEAR<\/strong>&nbsp;: We use the YEAR data type to store a year number, it stores values \u200b\u200bfrom 1 to 9999. Therefore, it is often used to store the date of birth or the start date of a contract, for example:<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>CREATE TABLE pessoas (\n  id INT PRIMARY KEY,\n  nascimento YEAR);\n\nINSERT INTO pessoas (id, nascimento) VALUES (1, 1990);<\/code><\/pre>\n\n\n\n<ol class=\"wp-block-list\" start=\"2\">\n<li><strong>MONTH<\/strong>&nbsp;: We use the MONTH data type to store a month number.&nbsp;Thus, it stores values \u200b\u200bfrom 1 to 12, for example:<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>CREATE TABLE pessoas (\n  id INT PRIMARY KEY,\n  nascimento MONTH);\n\nINSERT INTO pessoas (id, nascimento) VALUES (1, 1);\n<\/code><\/pre>\n\n\n\n<ol class=\"wp-block-list\" start=\"3\">\n<li><strong>DAY<\/strong>&nbsp;: We use the DAY data type to store a day of the week number.&nbsp;In this sense, it stores values \u200b\u200bfrom 0 to 6, where 0 represents Sunday and 6 represents Saturday, for example:<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>CREATE TABLE pessoas (\n  id INT PRIMARY KEY,\n  nascimento DAY);\n\nINSERT INTO pessoas (id, nascimento) VALUES (1, 0);<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"MySQL_geometric_data_types\"><\/span>MySQL geometric data types<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>MySQL geometric data types are used to store spatial geometry data such as points, lines, and polygons.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>POINT<\/strong>&nbsp;: The POINT data type is used to store a point on a surface.&nbsp;In this sense, represented by a tuple of values \u200b\u200b(x, y), where x and y are the latitude and longitude values \u200b\u200bof the point.<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>CREATE TABLE locations (\n  id INT PRIMARY KEY,\n  POINT position);\n\nINSERT INTO locations (id, position) VALUES (1, (10.5, -69.5));<\/code><\/pre>\n\n\n\n<p>In this example, the \u201cposition\u201d column is of type POINT and stores the location of a point on a surface.&nbsp;The value \u201c(10.5, -69.5)\u201d in this case represents the latitude and longitude of the point.<\/p>\n\n\n\n<ol class=\"wp-block-list\" start=\"2\">\n<li><strong>LINE<\/strong>&nbsp;: We use the LINE data type to store a line on a surface.&nbsp;Thus, represented by a sequence of points (x1, y1, x2, y2, \u2026), where each point represents a point on the line.&nbsp;See the example:<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>CREATE TABLE borders (\n  id INT PRIMARY KEY\n  LINE border);\n\nINSERT INTO borders (id, border) VALUES (1, ('0.0' ,'10.0', '10.10', '0.10', '0.0'));<\/code><\/pre>\n\n\n\n<p>Thus, in this example, the \u201cborder\u201d column is of type LINE and stores the location of a line on a surface.<\/p>\n\n\n\n<ol class=\"wp-block-list\" start=\"3\">\n<li><strong>POLYGON<\/strong>&nbsp;: We use the POLYGON data type to store a polygon on a surface.&nbsp;Thus, In this sense, represented by a sequence of lines (x1, y1, x2, y2, \u2026, xn, yn), where each line represents a point on the line.<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>CREATE TABLE polygons (\n  id INT PRIMARY KEY,\n  polygon POLYGON);\n\nINSERT INTO polygons (id, polygon) VALUES (1, POLYGON ('LINESTRING(-10.5 -69.5, 0 -69.5, 0 -10.5, -10.5 -69.5)'));<\/code><\/pre>\n\n\n\n<p>In this example, the \u201cpolygon\u201d column is of type POLYGON and stores the location of a polygon on a surface.<\/p>\n\n\n\n<ol class=\"wp-block-list\" start=\"4\">\n<li><strong>GEOMETRY<\/strong>&nbsp;: The GEOMETRY data type is a data type that supports several spatial geometry types, including POINT, LINE, and POLYGON.&nbsp;In this sense, we use it to store more complex spatial geometry data, such as curves and irregular polygons.<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Unicode_data_types\"><\/span>Unicode <code>data types<\/code><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>UTF-8<\/strong>&nbsp;: We use UTF-8 data type to store data in Unicode format in byte.<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>CREATE TABLE example_table (\n  id INT NOT NULL AUTO_INCREMENT,\n  name VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci,\n  PRIMARY KEY (id)\n);<\/code><\/pre>\n\n\n\n<p>In this example, we define the \u201cname\u201d column as type VARCHAR and uses the utf8mb4 character set, which handles blank characters up to 3 bytes, which includes most languages \u200b\u200band scripts.<\/p>\n\n\n\n<ol class=\"wp-block-list\" start=\"2\">\n<li><strong>UTF-16<\/strong>&nbsp;: We use UTF-16 data type to store data in Unicode format in 16 bits.&nbsp;Thus, In this sense, we use it a lot in applications that require more floating point precision.<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>CREATE TABLE example_table (\n  id INT NOT NULL AUTO_INCREMENT,\n  name VARBINARY(65535) CHARACTER SET utf16 COLLATE utf16_general_ci,\n  PRIMARY KEY (id)\n);<\/code><\/pre>\n\n\n\n<p>In this example, we define the \u201cname\u201d column as VARBINARY type and uses the utf16 character set, which handles blank characters of up to 2 bytes.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>MySQL, one of the leading relational database management systems, offers a variety of data types so that developers can store data of different types and formats.\u00a0Data management is fundamental to any information system, and\u00a0one of the most important aspects of data management is choosing the appropriate data type for each value stored in the database.\u00a0Additionally, [&hellip;]<\/p>\n","protected":false},"author":17,"featured_media":3883,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[91],"tags":[],"class_list":["post-3875","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-mysql"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v23.8 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>What are MySQL data types? - Copahost<\/title>\n<meta name=\"description\" content=\"Discover MySQL data types. Integers, decimals, text, datetime, binary choose correctly and ensure data integrity.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.copahost.com\/blog\/mysql-data-types\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"What are MySQL data types? - Copahost\" \/>\n<meta property=\"og:description\" content=\"Discover MySQL data types. Integers, decimals, text, datetime, binary choose correctly and ensure data integrity.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.copahost.com\/blog\/mysql-data-types\/\" \/>\n<meta property=\"og:site_name\" content=\"Copahost\" \/>\n<meta property=\"article:published_time\" content=\"2023-11-25T12:26:03+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-11-25T12:31:24+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.copahost.com\/blog\/wp-content\/uploads\/2023\/11\/dados-do-mysql-ingles.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1080\" \/>\n\t<meta property=\"og:image:height\" content=\"1080\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Schenia T\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Schenia T\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.copahost.com\/blog\/mysql-data-types\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.copahost.com\/blog\/mysql-data-types\/\"},\"author\":{\"name\":\"Schenia T\",\"@id\":\"https:\/\/www.copahost.com\/blog\/#\/schema\/person\/2efb96f9dfaf6162f347abcd06b1429f\"},\"headline\":\"What are MySQL data types?\",\"datePublished\":\"2023-11-25T12:26:03+00:00\",\"dateModified\":\"2023-11-25T12:31:24+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.copahost.com\/blog\/mysql-data-types\/\"},\"wordCount\":1422,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.copahost.com\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.copahost.com\/blog\/mysql-data-types\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.copahost.com\/blog\/wp-content\/uploads\/2023\/11\/dados-do-mysql-ingles.png\",\"articleSection\":[\"MySQL\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.copahost.com\/blog\/mysql-data-types\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.copahost.com\/blog\/mysql-data-types\/\",\"url\":\"https:\/\/www.copahost.com\/blog\/mysql-data-types\/\",\"name\":\"What are MySQL data types? - Copahost\",\"isPartOf\":{\"@id\":\"https:\/\/www.copahost.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.copahost.com\/blog\/mysql-data-types\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.copahost.com\/blog\/mysql-data-types\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.copahost.com\/blog\/wp-content\/uploads\/2023\/11\/dados-do-mysql-ingles.png\",\"datePublished\":\"2023-11-25T12:26:03+00:00\",\"dateModified\":\"2023-11-25T12:31:24+00:00\",\"description\":\"Discover MySQL data types. Integers, decimals, text, datetime, binary choose correctly and ensure data integrity.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.copahost.com\/blog\/mysql-data-types\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.copahost.com\/blog\/mysql-data-types\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.copahost.com\/blog\/mysql-data-types\/#primaryimage\",\"url\":\"https:\/\/www.copahost.com\/blog\/wp-content\/uploads\/2023\/11\/dados-do-mysql-ingles.png\",\"contentUrl\":\"https:\/\/www.copahost.com\/blog\/wp-content\/uploads\/2023\/11\/dados-do-mysql-ingles.png\",\"width\":1080,\"height\":1080,\"caption\":\"mysql data types\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.copahost.com\/blog\/mysql-data-types\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.copahost.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"What are MySQL data types?\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.copahost.com\/blog\/#website\",\"url\":\"https:\/\/www.copahost.com\/blog\/\",\"name\":\"Copahost\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/www.copahost.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.copahost.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.copahost.com\/blog\/#organization\",\"name\":\"Copahost\",\"url\":\"https:\/\/www.copahost.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.copahost.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.copahost.com\/blog\/wp-content\/uploads\/2016\/03\/copahostlogo.png\",\"contentUrl\":\"https:\/\/www.copahost.com\/blog\/wp-content\/uploads\/2016\/03\/copahostlogo.png\",\"width\":223,\"height\":40,\"caption\":\"Copahost\"},\"image\":{\"@id\":\"https:\/\/www.copahost.com\/blog\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.copahost.com\/blog\/#\/schema\/person\/2efb96f9dfaf6162f347abcd06b1429f\",\"name\":\"Schenia T\",\"description\":\"Data scientist, passionate about technology tools and games. Undergraduate student in Statistics at UFPB. Her hobby is binge-watching series, enjoying good music working or cooking, going to the movies and learning new things!\",\"url\":\"https:\/\/www.copahost.com\/blog\/author\/schenia\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"What are MySQL data types? - Copahost","description":"Discover MySQL data types. Integers, decimals, text, datetime, binary choose correctly and ensure data integrity.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.copahost.com\/blog\/mysql-data-types\/","og_locale":"en_US","og_type":"article","og_title":"What are MySQL data types? - Copahost","og_description":"Discover MySQL data types. Integers, decimals, text, datetime, binary choose correctly and ensure data integrity.","og_url":"https:\/\/www.copahost.com\/blog\/mysql-data-types\/","og_site_name":"Copahost","article_published_time":"2023-11-25T12:26:03+00:00","article_modified_time":"2023-11-25T12:31:24+00:00","og_image":[{"width":1080,"height":1080,"url":"https:\/\/www.copahost.com\/blog\/wp-content\/uploads\/2023\/11\/dados-do-mysql-ingles.png","type":"image\/png"}],"author":"Schenia T","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Schenia T","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.copahost.com\/blog\/mysql-data-types\/#article","isPartOf":{"@id":"https:\/\/www.copahost.com\/blog\/mysql-data-types\/"},"author":{"name":"Schenia T","@id":"https:\/\/www.copahost.com\/blog\/#\/schema\/person\/2efb96f9dfaf6162f347abcd06b1429f"},"headline":"What are MySQL data types?","datePublished":"2023-11-25T12:26:03+00:00","dateModified":"2023-11-25T12:31:24+00:00","mainEntityOfPage":{"@id":"https:\/\/www.copahost.com\/blog\/mysql-data-types\/"},"wordCount":1422,"commentCount":0,"publisher":{"@id":"https:\/\/www.copahost.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.copahost.com\/blog\/mysql-data-types\/#primaryimage"},"thumbnailUrl":"https:\/\/www.copahost.com\/blog\/wp-content\/uploads\/2023\/11\/dados-do-mysql-ingles.png","articleSection":["MySQL"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.copahost.com\/blog\/mysql-data-types\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.copahost.com\/blog\/mysql-data-types\/","url":"https:\/\/www.copahost.com\/blog\/mysql-data-types\/","name":"What are MySQL data types? - Copahost","isPartOf":{"@id":"https:\/\/www.copahost.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.copahost.com\/blog\/mysql-data-types\/#primaryimage"},"image":{"@id":"https:\/\/www.copahost.com\/blog\/mysql-data-types\/#primaryimage"},"thumbnailUrl":"https:\/\/www.copahost.com\/blog\/wp-content\/uploads\/2023\/11\/dados-do-mysql-ingles.png","datePublished":"2023-11-25T12:26:03+00:00","dateModified":"2023-11-25T12:31:24+00:00","description":"Discover MySQL data types. Integers, decimals, text, datetime, binary choose correctly and ensure data integrity.","breadcrumb":{"@id":"https:\/\/www.copahost.com\/blog\/mysql-data-types\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.copahost.com\/blog\/mysql-data-types\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.copahost.com\/blog\/mysql-data-types\/#primaryimage","url":"https:\/\/www.copahost.com\/blog\/wp-content\/uploads\/2023\/11\/dados-do-mysql-ingles.png","contentUrl":"https:\/\/www.copahost.com\/blog\/wp-content\/uploads\/2023\/11\/dados-do-mysql-ingles.png","width":1080,"height":1080,"caption":"mysql data types"},{"@type":"BreadcrumbList","@id":"https:\/\/www.copahost.com\/blog\/mysql-data-types\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.copahost.com\/blog\/"},{"@type":"ListItem","position":2,"name":"What are MySQL data types?"}]},{"@type":"WebSite","@id":"https:\/\/www.copahost.com\/blog\/#website","url":"https:\/\/www.copahost.com\/blog\/","name":"Copahost","description":"","publisher":{"@id":"https:\/\/www.copahost.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.copahost.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.copahost.com\/blog\/#organization","name":"Copahost","url":"https:\/\/www.copahost.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.copahost.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.copahost.com\/blog\/wp-content\/uploads\/2016\/03\/copahostlogo.png","contentUrl":"https:\/\/www.copahost.com\/blog\/wp-content\/uploads\/2016\/03\/copahostlogo.png","width":223,"height":40,"caption":"Copahost"},"image":{"@id":"https:\/\/www.copahost.com\/blog\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/www.copahost.com\/blog\/#\/schema\/person\/2efb96f9dfaf6162f347abcd06b1429f","name":"Schenia T","description":"Data scientist, passionate about technology tools and games. Undergraduate student in Statistics at UFPB. Her hobby is binge-watching series, enjoying good music working or cooking, going to the movies and learning new things!","url":"https:\/\/www.copahost.com\/blog\/author\/schenia\/"}]}},"_links":{"self":[{"href":"https:\/\/www.copahost.com\/blog\/wp-json\/wp\/v2\/posts\/3875","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.copahost.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.copahost.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.copahost.com\/blog\/wp-json\/wp\/v2\/users\/17"}],"replies":[{"embeddable":true,"href":"https:\/\/www.copahost.com\/blog\/wp-json\/wp\/v2\/comments?post=3875"}],"version-history":[{"count":6,"href":"https:\/\/www.copahost.com\/blog\/wp-json\/wp\/v2\/posts\/3875\/revisions"}],"predecessor-version":[{"id":3924,"href":"https:\/\/www.copahost.com\/blog\/wp-json\/wp\/v2\/posts\/3875\/revisions\/3924"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.copahost.com\/blog\/wp-json\/wp\/v2\/media\/3883"}],"wp:attachment":[{"href":"https:\/\/www.copahost.com\/blog\/wp-json\/wp\/v2\/media?parent=3875"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.copahost.com\/blog\/wp-json\/wp\/v2\/categories?post=3875"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.copahost.com\/blog\/wp-json\/wp\/v2\/tags?post=3875"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}