Code Monkey home page Code Monkey logo

db2csv's Introduction

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/

db2csv's People

Contributors

kchaitanya863 avatar harshitam996 avatar

Stargazers

 avatar

Watchers

James Cloos avatar  avatar

db2csv's Issues

Documentation

"For more details, see:" makes no sense. need to change that ASAP.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.