Convert mysql query results to CSV (with copy/paste) -


i work in command line mysql. common need take query's results , import them numbers document (similar excel document).

what fastest method doing this?

method 1: select outfile

you can select outfile directly mysql, takes several steps.

  1. export query necessary arguments make csv format, fields optionaly enclosed by , delimited by.
  2. sftp server , grab file
  3. delete file server

method 2: copy/paste

i tend method. me seems little faster that's because don't remember how construct select outfile query above , have up.

  1. copy/paste local text file
  2. open in text editor , replace | ,
  3. save csv , open in numbers.

how this?:

mysql -b -e "$my_query" > my_data.csv

the output format tab-separated rather comma-separated @ least excel , openoffice calc automatically adapt this.

btw, convenience , enable non-interactive execution of mysql commands, recommend setting secure ~/.my.cnf file
(readable you) entries this:

[client] user=your_mysql_user_name password=your_mysql_password host=your_mysql_server port=your_mysql_server_port whatever_other_options_you_like 

references:

http://dev.mysql.com/doc/refman/5.1/en/mysql-command-options.html

--batch, -b

print results using tab column separator, each row on new line. option, mysql not use history file.

batch mode results in nontabular output format , escaping of special characters. escaping may disabled using raw mode; see description --raw option.


Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -