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 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 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
How To Convert Image To Text In Google Docs Google Docs is a free online document editor provided by Google. Google Docs makes it easier to create a document for personal and professional uses with a variety of features. People often take photos of notes on the blackboard a billboard, or from a newspaper for using it later. These text content
11 min read
How to Get Column Names in MySQL? To get column names in MySQL use techniques such as the DESCRIBE statement, INFORMATION_SCHEMA.COLUMNS, and SHOW COLUMNS FROM commands. Here will cover these techniques, with explained examples, and help to get a better understanding on how to get column names in MySQL. MySQL Fetch Column Names from
3 min read
How to Export Query Result in MySQL? As a database administrator or developer, it is important to be able to store, manipulate, or analyze data outside of the database environment. Exporting query results from MySQL can be done in several ways, each with its advantages and applications. In this article, we will discuss two methods for
4 min read
How to Rename a Column in MySQL? Renaming columns in MySQL is a frequent task to keep data organized and flexible. It helps adjust database layouts to fit new needs without losing information. This article will show you different ways to rename columns in MySQL, making it easier to manage and update your database structure as your
4 min read
How to Import Data From a CSV File in MySQL? Importing data from a CSV (Comma-Separated Values) file into a MySQL database is a common task for data migration and loading purposes. CSV files are widely used for storing and exchanging tabular data. However, we cannot run SQL queries on such CSV data so we must convert it to structured tables. I
10 min read
How to Export a Table Data to a PDF File in SQL? SQL Server is a versatile database. It is used across many industries. We can use AZURE data studio as well as SQL Server Management Studio for doing various operations (DDL, DML, Stored Procedure, Trigger preparations) etc., SQL Server supports the portability of data using the EXPORT option. By de
2 min read