Skip to content

About

Python script to load data from a CSV file into a MySQL database table.

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Repository files navigation

mysql-csv-load

A Python CLI tool to load data from a CSV file into a MySQL database table using convention over configuration.

Features

  • Process CSV files in batches without loading the entire file into memory.
  • Convention over Configuration: The database table name is automatically inferred from the CSV filename (e.g., users.csv will load into the users table).
  • Environment variable support for secure database credentials.
  • Global terminal command execution after installation.

Installation

From local source

Clone the repository and install it using pip:

git clone https://github.com/relson/mysql-csv-load.git
cd mysql-csv-load
pip install .

Configuration

The application uses python-dotenv to manage database credentials. Create a .env file in your working directory with the following variables:

MYSQL_CSV_LOAD_HOST=localhost
MYSQL_CSV_LOAD_USER=your_user
MYSQL_CSV_LOAD_PASSWORD=your_password
MYSQL_CSV_LOAD_DATABASE=your_database_name
MYSQL_CSV_LOAD_PORT=your_database_port      # 3306 when empty or not set

Usage

After installation, the package registers a global command mysql-csv-load. Simply provide the path to your CSV file:

mysql-csv-load path/to/your/customers.csv

How it works: The command above will automatically parse customers.csv and attempt to load its content into a MySQL table named customers.

Large files are imported in batches without loading the entire CSV into memory. The default batch size is 1,000 rows; customize it with:

mysql-csv-load path/to/file.csv --batch-size 5000

Each batch is committed separately. If an error occurs, previously committed batches remain in the database; remove partial data before retrying.

About

Python script to load data from a CSV file into a MySQL database table.

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages