Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gossterrible/sql2csv

Repository files navigation

sql2csv

Go Report Card GoDoc Release License

A powerful command-line tool to export SQL database tables to CSV files. Supports MySQL, PostgreSQL, and SQLite databases with an interactive interface and concurrent exports.

Features

  • πŸ—ƒοΈ Support for multiple SQL database types:
    • MySQL/MariaDB
    • PostgreSQL
    • SQLite
  • πŸ”Œ Multiple connection methods:
    • Interactive connection details input
    • Connection string/URL support
    • SQL dump file import
  • πŸ“Š Interactive table selection with row count display
  • ⚑ Concurrent export of multiple tables
  • πŸš€ Efficient handling of large tables through batch processing
  • πŸ› οΈ User-friendly command-line interface
  • πŸ”’ Secure password handling

Installation

Using Go Install

go install github.com/gossterrible/sql2csv/cmd/sql2csv@latest

From Release Binary

Download the latest binary for your platform from the releases page.

Building from Source

# Clone the repository
git clone https://github.com/gossterrible/sql2csv.git
cd sql2csv
# Install dependencies
go mod download
# Build the binary
go build ./cmd/sql2csv
# Run tests
go test ./...

Usage

Quick Start

Simply run the tool and follow the interactive prompts:

sql2csv

Connection Methods

1. Direct Connection

$ sql2csv
? Select connection type: Direct Connection
? Select database type: postgres
? Enter database host: localhost
? Enter database port: 5432
? Enter database user: myuser
? Enter database password: ****
? Enter database name: mydb

2. Connection String

$ sql2csv
? Select connection type: Connection String
? Select database type: mysql
? Enter connection string: myuser:mypass@tcp(localhost:3306)/mydb

3. SQL Dump File

$ sql2csv
? Select connection type: SQL Dump File
? Enter SQL dump file path: ./dump.sql
? Select original database type: postgres

Example Output Structure

output_directory/
β”œβ”€β”€ users.csv
β”œβ”€β”€ products.csv
└── orders.csv

Database Support Details

MySQL/MariaDB

  • Supports all MySQL data types
  • Default port: 3306
  • Connection string format: user:password@tcp(host:port)/dbname
  • Required permissions: SELECT on target tables

PostgreSQL

  • Supports all PostgreSQL data types
  • Default port: 5432
  • Connection string format: postgresql://user:password@host:port/dbname
  • SSL mode disabled by default
  • Required permissions: SELECT on target tables and schema information

SQLite

  • Supports all SQLite data types
  • Connection format: Path to database file
  • No additional server setup needed
  • Read permissions required on the database file

Performance Optimization

The tool implements several optimizations for handling large datasets:

  • Batch processing to minimize memory usage
  • Concurrent table exports using Go routines
  • Efficient CSV writing with buffering
  • Connection pooling for better resource utilization

Contributing

Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

Development Requirements

  • Go 1.16 or later
  • CGO enabled (required for SQLite support)
  • Access to test databases (MySQL, PostgreSQL, SQLite) for integration testing

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

About

A powerful command-line tool to export SQL database tables to CSV files

Resources

License

Contributing

Stars

Watchers

Forks

Packages

Contributors

Languages

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /