Skip to content

This script converts MySQL database tables to Json and CSV files as an output files.

Notifications You must be signed in to change notification settings

devbabar/mysql_to_json_csv

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 

Repository files navigation

mysql_to_json_csv

This script converts MySQL database tables to Json and CSV files as an output files.

Steps to run this script:

Step 1.

Create a folder.

$ mkdir mysql_to_json_csv

Inside folder, create file mysql_to_json.py

Create a virtual enviroment.

$pip install virtualenv

$ cd mysql_to_json_csv

$ virtualenv env

$ source env/bin/activate

Step 2.

Install requirements.txt

$pip install -r requirements.txt

Step 3.

In order to establish the connection with database, edit the following function with your own database credentials.

'''----------- Function to establish a connection with database -----------'''

def dbconnect():

try:
   
   db = MySQLdb.connect(
       
       host="127.0.0.1",
       
       user="username", (database username)
       
       passwd="password", (database password)
    )
except Exception as e:
    sys.exit("Can't connect to Database")
return db

Step 4.

Open mysql_to_json file in PyCharm and run.

---- Demo ----

Database

This how our database "houseprice" and table "realestate" looks like.

First user input screen.

This screen will ask user to type filenames for Json and CSV output files.

Output files.

Running this will create output files.

Output CSV file.

Output Json file.

User input error handling.

Basic error handling applied. Users are only allowed to input string filename, not numbers. Warning keep prompting till get a correct filename.

About

This script converts MySQL database tables to Json and CSV files as an output files.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages