Skip to content

This script automates the process of loading data from a CSV file into a MySQL database and dumping the database into an SQL file for backup or migration. It uses Pandas for data manipulation and SQLAlchemy to interface with MySQL.

Notifications You must be signed in to change notification settings

Shivapande25/Converting-csv-files-into-SQL-DB

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 

Repository files navigation

MySQL Data Ingestion and Dump Script

Overview

This script automates the process of loading data from a CSV file into a MySQL database and dumping the database into an SQL file for backup or migration. It uses Pandas for data manipulation and SQLAlchemy to interface with MySQL.

Features

  • Connects to a MySQL database.
  • Automatically creates a database if it doesn't exist.
  • Loads data from a CSV file into a specified table in the database.
  • Exports the entire database to an SQL file with the necessary CREATE DATABASE and USE statements for easy restoration.

Requirements

  • Python 3.x
  • pandas
  • mysql-connector-python
  • SQLAlchemy

Installation

  1. Install the required Python libraries using pip:

    pip install pandas sqlalchemy mysql-connector-python
  2. Make sure MySQL is installed and accessible from your machine.

Usage

  1. Edit the script and replace the placeholders (your_username, your_password, your_host, your_port, your_database, etc.) with your actual MySQL credentials and file paths.
  2. Run the script to load data from a CSV file into your MySQL database:
    python your_script_name.py
    
  3. The script will also create an SQL dump file, which can be used to restore the database later.

Output

  1. The data from the CSV file will be written to a MySQL table.
  2. The database will be dumped into an SQL file with the necessary CREATE DATABASE and USEstatements.

Example

CREATE DATABASE IF NOT EXISTS my_database;
USE my_database;

About

This script automates the process of loading data from a CSV file into a MySQL database and dumping the database into an SQL file for backup or migration. It uses Pandas for data manipulation and SQLAlchemy to interface with MySQL.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages