How to Convert From BLOB to Text in MySQL?
Last Updated :
28 Nov, 2021
In this article, we will see the conversion of a BLOB to TEXT in MySQL.
BLOB: It stands for Binary Large Object. It is a kind of data type in MySQL that can store files or images in the database in binary format. It has four types i.e TINYBLOB, BLOB, MEDIUMBLOB, and LONGBLOB. All four types are similar, the only difference among them is the amount of data they can hold.
AS the name suggests, LONGBLOB can hold the maximum amount of data and TINYBLOB can hold the least amount of data among the four types.
TEXT datatype in MySQL is used for storing long text strings in the database. It is just like VARCHAR. In order to convert BLOB to TEXT, we will use the CONVERT statement.
Syntax:
CONVERT( column_name using utf8);
utf8 is the way of encoding Unicode characters. It is recommended to use ut8 while creating web pages and databases. For demonstration, follow the below steps:
Step 1: Create a database
we can use the following command to create a database called geeks.
Query:
CREATE DATABASE geeks;

Step 2: Use database
Use the below SQL statement to switch the database context to geeks:
Query:
USE geeks;

Step 3: Table definition
We have demo_table in our geek’s database.
Query:
CREATE TABLE demo_table(
NAME VARCHAR(20),
AGE INT,
CITY VARCHAR(20),
FILE BLOB);

Step 4: Insert data into a table
Query:
INSERT INTO demo_table VALUES ('Romy', 21,
'Delhi', 'My name is romy kumari,
I am 21 yrs old'),
('Pushkar', 22, 'Delhi',
'My name is Pushkar jha,
I am 22 yrs old'),
('Rinkle', 22, 'Punjab',
'My name is Rinkle Arora,
I am 22 yrs old'),
('Ayushi', 22, 'Patna', 'My name is
Ayushi choudhary, I am 22 yrs old');
Step 5: View the content
Execute the below query to see the content of the table
Query:
SELECT * FROM demo_table;
Output:

We can see that content of the FILE column is in encoded format.
Step 6: Conversion from BLOB to TEXT.
Query:
SELECT convert(File using utf8)
from demo_table;

If you want to update the BLOB datatype column to the TEXT datatype column. Follow these steps:
- Alter the table and add a column having data type TEXT.
- Add content to that column after converting BLOB data to TEXT date.
- Drop BLOB column.
Step 1: Add column
Syntax:
ALTER Table demo_table ADD
COLUMN AFTER_CONERSION TEXT;

Step 2: Add content to column
UPDATE demo_table SET AFTER_CONERSION
= CONVERT (FILE using utf8);

Step 3: Drop BLOB column
ALTER TABLE demo_table
DROP COLUMN FILE;
Similar Reads
How to Convert MySQL Table Field Type from BLOB to JSON?
In this article, we would be learning a MySQL query to convert a field of BLOB Data Type to JSON Data Type in a table. To execute this query, we would need to alter the table and subsequently the field's definition. We would first need to use the ALTER TABLE command to start making changes to the ta
2 min read
How to Convert Timestamp to Datetime in MySQL?
In this article, we are going to learn how to convert Timestamp to Datetime in MySQL.To execute these queries, we need to first add integer data(written in timestamp format) and then use the FROM_UNIXTIME() function to convert it into "Datetime" Data Type. FROM_UNIXTIME(): This function in MySQL ret
2 min read
How to Convert BLOB into VARCHAR in MySQL?
In this article, we would be learning a SQL query to convert a column of BLOB Data Type to VARCHAR Data Type. To execute this query we would need to alter the table and subsequently a column's definition. We would first need to use the ALTER TABLE command to change the table. ALTER TABLE: ALTER TABL
2 min read
How to Convert JSON to Blob in JavaScript ?
This article explores how to convert a JavaScript Object Notation (JSON) object into a Blob object in JavaScript. Blobs represent raw data, similar to files, and can be useful for various tasks like downloading or processing JSON data. What is JSON and Blob?JSON (JavaScript Object Notation): A light
2 min read
How to Convert Base64 to Blob in JavaScript?
Working with files and data in web applications often involves dealing with binary data. One common scenario is converting a Base64 string into a Blob object, which can then be used in various ways, such as creating downloadable files or uploading images to a server. This article will guide you thro
4 min read
How to Convert Blob Data to JSON in JavaScript ?
When dealing with Blob data in JavaScript, such as binary data or files, we may need to convert it into JSON format for doing so JavaScript provides us with various methods as listed below. Table of Content Using FileReader APIUsing TextDecoder APIUsing FileReader APIIn this approach, we first use t
2 min read
How to Convert Rows into Columns in MySQL?
Converting rows into columns, also known as pivoting or transposing, is a common operation in DBMS, and MySQL provides robust functionality for achieving this transformation. This process is useful to reshape data for better analysis or reporting. This guide will explore the syntax, usage, and examp
3 min read
How to Strip Time Component From Datetime in MySQL?
MySQL is a very popular open-source and free database server that is ideal for small and large applications and is a relational database management system where SQL (Structured Query Language) queries or statements are used to manage and manipulate the data. MySQL provides many built-in functions li
4 min read
How to Connect to MySQL Server
MySQL is a widely utilized open-source relational database management system (RDBMS) known for its popularity and effectiveness in handling and structuring massive amounts of data. If you are a developer, data analyst, or someone who needs to store and manage data, MySQL is a highly adaptable and de
5 min read
How to Concat Two Columns Into One in MySQL?
Concatenating columns in MySQL is a key operation for combining data from multiple fields into a single, unified column. This process is essential for generating comprehensive reports and merging data elements like names or addresses. This article explores two effective methods for column concatenat
3 min read