EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 360+ Courses All in One Bundle
  • Login
Home Data Science Data Science Tutorials MySQL Tutorial MySQL TEXT 
Secondary Sidebar
MySQL Tutorial
  • Functions
    • MySQL Function
    • MySQL Aggregate Function
    • MySQL String functions
    • MySQL Date Functions
    • MySQL Window Functions
    • MySQL Math Functions
    • MySQL Boolean
    • Cursor in MySQL
    • Condition in MySQL
    • MySQL BETWEEN
    • Insert in MySQL
    • MySQL IFNULL()
    • MySQL TIMESTAMPDIFF()
    • MySQL COALESCE()
    • MySQL count()
    • MIN() in MySQL
    • MySQL Numeric
    • MySQL field()
    • MySQL FIND_IN_SET()
    • MySQL avg()
    • MySQL MAX() Function
    • MySQL BIN()
    • MySQL Concat
    • MySQL DECODE()
    • MySQL REGEXP_REPLACE()
    • MySQL Asynchronous
    • MySQL innodb_buffer_pool_size
    • MySQL key_buffer_size
    • MySQL TRUNCATE()
    • MySQL ROW_NUMBER()
    • NOT in MySQL
    • MySQL IN Operator
    • LIKE in MySQL
    • ANY in MySQL
    • MySQL NOT IN
    • MySQL CHECK Constraint
    • MySQL DISTINCT
    • MySQL ALL
    • MySQL Union
    • MySQL UNION ALL
    • MySQL EXISTS
    • MySQL ON DELETE CASCADE
    • MySQL REGEXP
    • MySQL Index
    • MySQL Add Index
    • MySQL REINDEX
    • MySQL UNIQUE INDEX
    • MySQL Clustered Index
    • MySQL? InnoDB Cluster
    • Table in MySQL
    • ALTER TABLE MySQL
    • MySQL Temporary Table
    • MySQL Clone Table
    • MySQL Repair Table
    • MySQL Lock Table
    • MySQL Optimize Table
    • TRUNCATE TABLE MySQL
    • MySQL?Table?Size
    • MySQL Table Dump
    • MySQL Update Set
    • MySQL ALTER TABLE Add Column
    • MySQL RANK()
    • MySQL CTE
    • MySQL LAG()
    • MySQL GROUP_CONCAT()
    • MySQL EXTRACT()
    • MySQL REPLACE
    • MySQL AUTO_INCREMENT
    • MySQL SYSDATE()
    • MySQL NULLIF()
    • MySQL Substring
    • MySQL SUBSTRING_INDEX()
    • MySQL LOWERCASE
    • MySQL Row
    • MySQL NOW
    • MySQL CEIL
    • MySQL Alias
    • MySQL Trigger
    • MySQL SHOW Triggers
    • MySQL UPDATE Trigger
    • MySQL DELETE Trigger
    • MySQL AFTER UPDATE Trigger
    • MySQL Stored Procedure
    • ROLLUP in MySQL
    • MySQL? INSTR()
    • MySQL Subquery
    • MySQL Timestamp
    • MySQL? Hour()
    • MySQL MOD()
    • MySQL DATE_FORMAT()
    • ALTER Column in MySQL
    • MySQL Rename Column
    • MySQL Interval
    • MySQL CURDATE
    • MySQL BIT
    • MySQL Binlog
    • MySQL Average
    • MySQL TEXT
    • MySQL SHOW
    • MySQL Offset
    • MySQL Timezone
    • mysql_real_escape_string
    • MySQL Datetime
    • MySQL DATE_SUB()
    • MySQL FULLTEXT
    • MySQL DATE_ADD()
    • MySQL sum()
    • MySQL Merge
    • MySQL BigInt
    • MySQL ROUND
    • MySQL VARCHAR
    • MySQL Decimal
    • MySQL Limit
    • MySQL today()
    • MySQL WEEKDAY
    • MySQL Split
    • MySQL Create Function
    • MySQL BLOB
    • MySQL encode()
    • MySQL Primary Key
    • MySQL Foreign Key
    • Unique Key in MySQL
    • MySQL Drop Foreign Key
    • MySQL DROP TRIGGER
    • MYSQL Database
    • Delete Database MySQL
    • MySQL Root
    • MySQL Root Password
    • MySQL Client
    • MySQL Users
    • MySQL?User Permissions
    • MySQL add user
    • MySQL List User
    • MySQL Show Users
    • MySQL User Password
    • MySQL?Cardinality
    • MySQL Workbench
    • MySQL Backup
    • MySQL REVOKE
    • MySQL Dump
    • MySQL Cluster
    • MySQL Full Text Search
    • MySQL Admin Tool
    • MySQL Export Database
    • MySQL Export to CSV
  • Basic
    • MySQL floor
    • MySQL DESCRIBE table
    • MySQL encryption
    • Introduction to MySQL
    • Is SQL Server a Database?
    • What is MySQL
    • Is MySQL Programming Language
    • MySQL Server
    • MySQL AB
    • MySQL Community Server
    • How To Install MySQL
    • MySQL Versions
    • MySQL OpenSource
    • MySQL GUI Tools
    • MySQL Grant
    • MySQL Error 1064
    • MySQL Drop Database
    • MySQL not equal
    • MySQL SELECT INTO Variable
    • MySQL Commands
    • MySQL Operators
    • What is MySQL Schema
    • Wildcards in MySQL
    • MySQL Constraints
    • MySQL Administration
    • MySQL Data Type
    • MYSQL COMMIT
    • MySQL FORMAT
    • Timestamp to Date in MySQL
    • MySQL DATEDIFF
    • MySQL?Incremental Backup
    • MySQL JSON Data Type
    • MySQL ENUM
    • MySQL Default Port
    • Cheat Sheet MySQL
  • Queries
    • MySQL Queries
    • MySQL Query Commands
    • SELECT in MySQL
    • MySQL INSERT IGNORE
    • MySQL having
    • ORDER BY in MySQL
    • MySQL Cheat Sheet
    • MySQL ORDER BY Random
    • MySQL ORDER BY DESC
    • MySQL GROUP BY
    • MySQL GROUP BY Count
    • MySQL GROUP BY month
    • MySQL WHERE Clause
    • MySQL WITH
    • MySQL FETCH
    • MySQL DDL
    • MySQL DML
    • MySQL WHERE IN Array
    • MySQL Fetch Array
    • MySQL ISNULL
    • MySQL Index Types
    • Mysql? Export Schema
    • Amazon RDS for MySQL
    • MySQL greatest
  • Database
    • What is Data Modeling
    • What is Data Processing
    • DBMS Architecture
    • DBMS Keys
    • Careers in Database Administration
    • What is MySQL Database
    • MySQL Relational Database
    • How to Connect Database to MySQL
    • MySQL Database Repair
    • RDBMS Interview Questions
    • DBMS Interview Questions
  • Joins
    • Joins in MySQL
    • MySQL Outer Join
    • Left Outer Join in MySQL
    • MySQL Self Join
    • Natural Join in MySQL
    • MySQL DELETE JOIN
    • MySQL Update Join
    • MySQL Cross Join
  • Advanced
    • MySQL Formatter
    • MySQL TINYINT
    • MySQL Grant All Privileges
    • MySQL DROP TABLE
    • MySQL rename database
    • MySQL Flush Privileges
    • MySQL super Privilege
    • MySQL Character Set
    • MySQL Log File
    • MySQL Flush Log
    • Grant Privileges MySQL
    • MySQL WHILE LOOP
    • IF Statement in MySQL
    • MySQL CASE Statement
    • MySQL IF Function
    • MySQL IF EXISTS
    • MySQL UUID
    • Views in MySQL
    • MySQL Replication
    • MySQL Partition
    • Toad for MySQL
    • Navicat for MySQL
    • MySQL AES_Encrypt
    • MySQL Performance Tuning
    • MySQL Transaction
    • MySQL? sort_buffer_size
    • MySQL? Sync
    • MySQL? Query Cache
    • MySQL Collation
    • MySQL ODBC Driver
    • MySQL Partitioning
    • MySQL InnoDB
    • MySQL Float vs Decimal
    • MySQL Union vs Union All
  • Interview Questions
    • MySQL Interview Questions

MySQL TEXT 

By Aanchal SharmaAanchal Sharma

MySQL TEXT 

Definition of MySQL TEXT

Normally, in MySQL, the data type defines the category of value a table column can embrace. It can be an integer, float, date, varchar, time, character, money, binary, etc. Here, we can explain MySQL TEXT Data type as a Database object that is responsible for storing text strings in long-form into the table records. Essentially, MySQL TEXT can be recognized as a family of table column type which is proposed to provide the higher capability of character storing in MySQL ranging between 1 byte to 4GB.

Apart from the character data types VARCHAR and CHAR, MySQL supports with type TEXT which adds more structures that cannot be covered by the previous ones mentioned. This is also useful for keeping the article body in a broadcast related website or explanation of products in any e-commerce website.

Start Your Free Data Science Course

Hadoop, Data Science, Statistics & others

Syntax of MySQL TEXT

Syntax of mysql text is given below:

We have introduced a basic syntax code succeeding to illustrate the TEXT data type in MySQL. We can use TEXT while creating a table using the following query structure:

CREATE TABLE TableName (ID INT PRIMARY KEY AUTO_INCREMENT, Title VARCHAR (255) NOT NULL, Description TEXT[forms]NOT NULL);

Here, we have added some columns with TEXT and other data types where ’ forms’ says you can add other forms of TEXT that are explained later in the table with name as TableName(provide table name as desired).

Again, the use of TEXT with ALTER keyword by the below query syntax:

ALTER TABLE TableName
ADD COLUMN ColName TEXT NOT NULL AFTER Description;

In the above code, when executed it will add a new column ColName (specify any column name as desired) with data type as TEXT but after the column named Description that was created by the previous query while creating table.

How does TEXT Data Type Work in MySQL?

MySQL TEXT is a standard data type for storing special character strings with maximum sizes or as defined. On the ordering of its character set, the evaluations and sorting are built. In actual, this TEXT data type for a column is composed of four categories. They are TINYTEXT, TEXT, MEDIUMTEXT, LONGTEXT. These all types of TEXT are identical to each other but differ with a slight variation that is with the maximum capacity or volume of data values each one can hold.

This data type TEXT can be said just like the MySQL VARCHAR but the former column do not exist with DEFAULT values as succeeding ones. For info, CHAR contains a fixed length of strings defined from 0 to 255 and VARCHAR has a flexible length string defined from 0 to 65535.

  • Here, TINYTEXT is the smallest TYPE OF TEXT kind and defines the identical character length as MySQL VARCHAR type. It holds max 255 characters length of string that supports to build up storage for small info strings resourcefully.
  • The TEXT data type has a size of string characters upto 65,535 bytes to manage classic long-form contents of the text.
  • MEDIUMTEXT has a size of string characters up to 16,777,215 which is helpful to store longer text strings such as books, code backup, and white papers.
  • LONGTEXT has size definition up to max 4,294,967,295 characters which is used to store text strings up to the extreme length. It is supported in applications and computer programs.

Unlike VARCHAR and CHAR types, for a column having TEXT data type you do not need to state a string character length for using it. Also, different from VARCHAR and CHAR, MySQL does not delete or swabspaces when we insert or fetch columns with TEXT data values. It should be noted that the MYSQL TEXT data is not kept in the memory of the database server. Thus, MySQL will have to narrate it from the disk every time we query or execute the TEXT data. This is then much leisurelier in the evaluation process.

You will sustain performance hits while using TEXT columns for search and select queries in MySQL because the objects will be called individually by the server and needs scanning during the execution of queries. For this, we can use as a substitute of paging data stored in the server’s memory. If we enable strict SQL then, it will impose the character lengths to the maximum and removes any inserted data that surpasses those restrictions.

But you will find a huge difference between VARCHAR and TEXT that is the VARCHAR columns can be indexed but TEXT columns cannot. MySQL TEXT type helps to store computational data and also to display a considerable quantity of material for tasks like searching columns, sorting, and maybe for managing minor configuration based selections for a large development.

Examples of MySQL TEXT

Let us demonstrate some of the working of MySQL TEXT Data type in MySQL using effective examples explained below:

Example #1

Example to show a declaration of a column in the database table as TEXT:

We have implemented the following CREATE query statement having a TEXT data type column:

CREATE TABLE Article_Demo (ID INT PRIMARY KEY AUTO_INCREMENT, Title VARCHAR (25) NOT NULL, Intro TEXT NOT NULL);

Output:

MySQL TEXT -1.1

Now, using the DESCRIBE Keyword we will view the table information as follows:

DESCRIBE Article_Demo;

Output:

MySQL TEXT -1.2

Example #2

Example to create a table column having TINYTEXT type:

CREATE TABLE MagazineDemo (ID INT PRIMARY KEY AUTO_INCREMENT, Title VARCHAR (255) NOT NULL, BriefTINY TEXT NOT NULL);

Output:

MySQL TEXT -2.1

Also,

DESCRIBE MagazineDemo;

Output:

Output -2.2

Example #3

Example to add a new column with TEXT type using ALTER statement:

Let us suppose that we are adding long content as a body to the above-created table Article_Demo. So, we need to supplement a column with a TEXT data type named Description by applying the succeeding query in the server:

ALTER TABLE Article_Demo
ADD COLUMN Description TEXT NOT NULL AFTER Intro;

Output:

Output -3.1

Also,

DESCRIBE Article_Demo;

Output:

Output -3.2

Likewise, for large text storage like for books or more, we can implement MEDIUMTEXT and LONGTEXT respectively in MySQL.

Conclusion

In MySQL, every column defined in a table requires a unique name along with its data type that represents a guideline for Database to understand what type of data is to be specified inside a column to perform any query command or action. So, here we have learned about an important data type MySQL TEXT which holds a string with a defined capacity or length accordingly.

Recommended Articles

This is a guide to MySQL TEXT. Here we also discuss the definition and how does text data type work in mysql? done along with examples and its code implementation. You may also have a look at the following articles to learn more –

  1. MySQL Index
  2. MySQL Date Functions
  3. IF Statement in MySQL
  4. MySQL Trigger
Popular Course in this category
MySQL Training Program (12 Courses, 10 Projects)
  12 Online Courses |  10 Hands-on Projects |  92+ Hours |  Verifiable Certificate of Completion
4.5
Price

View Course

Related Courses

MS SQL Training (16 Courses, 11+ Projects)4.9
Oracle Training (17 Courses, 8+ Projects)4.8
PL SQL Training (4 Courses, 2+ Projects)4.7
Primary Sidebar
Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Database Management
  • Machine Learning
  • All Tutorials
Certification Courses
  • All Courses
  • Data Science Course - All in One Bundle
  • Machine Learning Course
  • Hadoop Certification Training
  • Cloud Computing Training Course
  • R Programming Course
  • AWS Training Course
  • SAS Training Course

ISO 10004:2018 & ISO 9001:2015 Certified

© 2023 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA Login

Forgot Password?

By signing up, you agree to our Terms of Use and Privacy Policy.

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more