Python script to convert csv files to mysql database tables.
This project is a python script to convert csv files to mysql database tables. Only tested on Linux, LMDE 5, Debian 10.
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.
As stated in Getting Started, this project was only tested on Linux, LMDE 5, Debian 10, so built-in tools may not be available on other systems. Please create an issue if you have any problems. Other than that, you'll need to install the following dependencies (you'll find step-by-step instructions for the Python packages in the Installing section below):
- Python 3.7 or higher
- pip (Python package manager) <-- I used debian's package manager to install this
- Python packages:
- sqlalchemy
- pandas
- numpy
- MySQL server (version 8.0.23) <-- I used debian's package manager to install this
- MySQL Workbench (version 8.0.23) <-- I used debian's package manager to install this
It is recommended to use a virtual environment to install the dependencies. The following instructions will install the dependencies in a virtual environment. You should also have a MySQL server running on your machine. You can download it from here. Instructions for setting up a MySQL server can be found here.
Here's a list of the installation steps required to get the project up and running, it's assumed that you already have Python 3.7 or higher, pip, and venv installed. If you don't, please refer to the Prerequisites section above or the Python documentation:
-
Clone the repository and cd into the project directory
-
Create and activate a virtual environment
-
Install the dependencies
-
Create a MySQL database
-
Run the script
-
Clone the repository and cd into the project directory
git clone https://github.com/Anzo52/csv2mysql.git
cd csv2mysql
- Create and activate a virtual environment
python3 -m venv venv
source venv/bin/activate
- Install the dependencies
pip install -r requirements.txt
- Create a MySQL database
mysql -u root -p
CREATE DATABASE [database_name];
- Run the script (you'll be prompted to enter the database name, username, and password. Make sure to use the same database name you used in step 4)
python3 csv2mysql.py
- Python - Programming language
- pandas - Data analysis and manipulation tool
- numpy - Scientific computing package
- sqlalchemy - SQL toolkit and Object Relational Mapper