Skip to content

kchaitanya863/db2csv

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 

Repository files navigation

db2csv

Convert your MySQL / PostgreSQL tables/queries to csv. Options include:

  • setting resultset fetch size(number of records to fetch from db in a single network call)
  • setting CSV Delimiter
  • setting CSV Quote character
  • supports SSL connection
  • dump all tables in a database
  • dump all in a PostgreSQL schema

Need Contributers for:

  • compiling it to an executable with GraalVM
  • adding more database providers

Install Groovy first

sudo apt-get install groovy

Run this script without cloning

groovy https://raw.githubusercontent.com/kchaitanya863/db2csv/master/db2csv.groovy

Download single table in the database

groovy db2csv.groovy -h <db_hostname> -u <username> -p <password> -d database_name -t table_name

Download all tables in the database

groovy db2csv.groovy -h localhost -u root -p root -d database_name -a

Download from query

groovy db2csv.groovy -h localhost -u root -p root -d database_name -q "select * from test where id < 40"

      _ _    ___                
     | | |  |__ \               
   __| | |__   ) |_________   __
  / _| | '_ \ / // __/__\ \ / /
 | (_| | |_) / /| (__\__ \\ V / 
  \__,_|_.__/____\___|___/ \_/  
                                
                                
Usage: db2csv [-?asv] [--client=<client>] [--delimiter=<delimiter>]
              [--escape=<csvEscapeCharacter>] [--quote=<quoteCharacter>]
              [--schema=<schema>] -d=<database> -h=<hostname>
              [-o=<outputFolder>] -p=<password> [-port=<port>] [-q=<query>]
              [-r=<resultSetfetchSize>] [-t=<table>] -u=<username>
Get Database tables as csv
      --client=<client>   select client MySQL or PostgreSQL
                            Default: MySQL
      --delimiter=<delimiter>
                          CSV delimiter.
                            Default: ,
      --escape=<csvEscapeCharacter>
                          CSV Quote Character.
                            Default: "
      --quote=<quoteCharacter>
                          CSV Quote Character.
                            Default: "
      --schema=<schema>   PostgreSQL Schema.
                            Default: public
  -?, --help              Show this help message and exit.
  -a, --all               download all tables in the database
  -d, --database=<database>
                          database name to use.
  -h, --host=<hostname>   hostname of the database server.
  -o, --output=<outputFolder>
                          path to output
  -p, --password=<password>
                          password to the database server.
      -port=<port>        port of the database server.
                            Default: 3306
  -q, --query=<query>     query to save. ex.: select * from tableName where id < 6;
  -r, --resultSetfetchSize=<resultSetfetchSize>
                          Number of records to fetch from server in one call
                            Default: 200
  -s, --ssl               use ssl connection to the server
  -t, --table=<table>     table to save.
  -u, --user=<username>   username of the database server.
  -v, --verbose           Print more info on execution

============================
Developed by @kchaitanya863
ASCII Art thanks to http://patorjk.com/software/taag/

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages