Import Data from Excel into MySQL using Python
Published in
3 min readFeb 5, 2021
Hello World!
In this blog i will explain how to import data from Excel file into MySQL. Let’s see the implementation in Python.
Python Module Used:
- pymysql : pyMySQL is a python library for connecting to a MySQL database server from Python.This module has lots of features like it mad CRUD operations simple.
To use this library you need to install. For installation use below command
pip install PyMySQL
If you want to know more pymysql then refer pyMySQL documentations using below link
- xlrd : xlrd is a python library for reading data and formatting information from Excel file.
To install this library use below command:
pip install xlrd
For more follow xlrd documentations.
Let’s Code:
- In order to use these libraries we need to import first,so let’s import first.
- Connect with your Database
- After connecting to database we need to create table
- Execute create table query
- Read Excel sheet
- we can also print the sheet name and sheet number as well
- Now write Insert query
- Now last step read each and every value from excel sheet and and execute insert query.
Here is Data in Our DB:
You can check this code at my GitHub Repository
Thank you for reading.Do share your valuable suggestions, I appreciate your honest feedback!