Skip to content

Script to convert a sql file from a mysql dump to csv files for python3, preserving the table name, headers and handling multiple insert statements per table. Largely based on the python2.7 script by jamesmishra, which can be found at https://github.com/jamesmishra/mysqldump-to-csv.

License

Notifications You must be signed in to change notification settings

srozb/mysql_dump_to_csv_python3

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 

Repository files navigation

MySQL dump to CSV for python3

Background

A quick and dirty python script to convert the SQL file from a mysqldump to multiple csv files for python3

It is largely based on the mysql_dumpt_to_csv project by the GitHub user jamesmishra. I've added a couple of bits of functionality:

  1. The csv files are named according to the table name in the CSV file
  2. The headers of the SQL tables are preserved
  3. Multiple insert statements are handled correctly

Usage

Run python sql_to_csv.py followed by the filename of the SQL file

How It Works

Every line is checked for the 'CREATE TABLE' and 'INSERT INTO' statements. If the first statement is observed, the following lines are extracted to obtain the headers of the SQL table. If the second statement is observed, the rest of the line is converted to CSV.

About

Script to convert a sql file from a mysql dump to csv files for python3, preserving the table name, headers and handling multiple insert statements per table. Largely based on the python2.7 script by jamesmishra, which can be found at https://github.com/jamesmishra/mysqldump-to-csv.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%