![]() |
VOOZH | about |
In Python Programming, We can connect with several databases like MySQL, Oracle, SQLite, etc., using inbuilt support. We have separate modules for each database. We can use SQL Language as a mediator between the python program and database. We will write all queries in our python program and send those commands to the database. So, Using these programs, we can perform several operations such as Insertion, Deletion, Updating, and Retrieving.
Here, In this article, We will discuss working with MySQL BLOB in python. With the help of BLOB(Large Binary Object) data type in MySQL, we can store files or images in our database in binary format.
This connector will connect our python program to database. Just run this command,
pip install mysql-connector-python
import mysql.connector
connection = mysql.connector.connect(host='localhost', database='<database_name>', user='<User_name>', password='<password>')
cursor = connection.cursor()
cursor.execute("select * from table_name")cursor.close() con.close()
We are done with the basic steps of connection. Now, Let's discuss the main agenda of this article which is the practical implementation of BLOB data type in MySQL Python,
create database geeksforgeeks;
For Example:
We are done with all basic which is required. Let's see the complete code for inserting the images or files in the MySQL database using Python Programs:
Output:
The table formed in MySQL:
Explanation:
Click here to download PNG file and TXT file.