#TIL : Export MySQL data by specified query to CSV file

To export data from MySQL by specified query to CSV file, you can use this command

1
$ mysql -B -u username -p database_name -h dbhost -e "SELECT * FROM table_name;" | sed "s/'/\'/;s/\t/\",\"/g;s/^/\"/;s/$/\"/;s/\n//g"

Tip from : https://stackoverflow.com/a/25427665

#TIL : Mycli : a new good cli MySql Client

This tool is written in Python with super cool features (auto-complete and colors).

Worth a shot !

Install

1
$ pip install mycli

Usage

1
$ mycli -h 127.0.0.1 -P 3306 -u root

Screencast

mycli