SkillAgentSearch skills...

CSVtoMySQL

This Python script allows you to import data from a CSV file into a MySQL database. It provides a user-friendly interface to input the database name, table name, and column names for the table. The script dynamically creates the table in the MySQL database with the specified columns and their data types.

Install / Use

/learn @brick-24/CSVtoMySQL

README

CSV to MySQL

Build Status License: MIT Python Version

Demo

image

Outdated docs

CSV to MySQL is a simple Python utility that allows you to import data from a CSV file into a MySQL database. This tool checks if the specified database exists and creates it if it doesn't, then creates a table and imports the data from the CSV file.

  • https://commando2406.github.io/CSVtoMySQL/

Features

  • Connect to MySQL database
  • Check and create database if it doesn't exist
  • Create table based on CSV header
  • Import CSV data into MySQL table

Table of Contents

Installation

Prerequisites

  • Python 3.x
  • MySQL server
  • mysql-connector-python library

Steps

  1. Clone the repository:

    git clone https://github.com/COMMANDO2406/CSVtoMySQL.git
    cd CSVtoMySQL
    
  2. Install the required Python packages:

    pip install mysql-connector-python
    
  3. Create a config.py file:

    # config.py
    host = 'your_mysql_host'
    user = 'your_mysql_user'
    password = 'your_mysql_password'
    
  4. Prepare your CSV file: Ensure you have a CSV file named main.csv in the same directory as the script. The CSV file should have a header row with column names matching the ones you will specify in the script.

Usage

  1. Run the script:

    python csv_to_mysql.py
    
  2. Enter the required information when prompted:

    • Database name: Enter the name of the database you want to use. If it doesn't exist, it will be created.
    • Table name: Enter the name of the table where the data will be imported.
    • Column names: Enter the column names separated by commas. These should match the columns in your CSV file.

Example

Here is an example of how to use the script:

  1. Prepare your CSV file (main.csv):

    name,age,city
    Alice,30,New York
    Bob,25,Los Angeles
    
  2. Run the script:

    python csv_to_mysql.py
    
  3. Enter the following when prompted:

    Enter database name: my_database
    Enter table name: people
    Enter column names (Separated by commas): name,age,city
    
  4. The script will output:

    Connected successfully
    Database 'my_database' created successfully
    Data imported successfully.
    
View on GitHub
GitHub Stars4
CategoryData
Updated3mo ago
Forks0

Languages

Python

Security Score

87/100

Audited on Dec 13, 2025

No findings