Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I export a MySQL db structure to an Excel file?

Tags:

mysql

excel

Is there any tool to export a MySQL db structure to an Excel file? For example:

1   ID  int(10)  not null  pri   0  index   comment

Thanks for any help.

like image 878
Long Vu Avatar asked Aug 01 '13 08:08

Long Vu


1 Answers

You could query information_schema.columns to obtain the required data:

SELECT * from information_schema.columns
WHERE table_schema = 'db_2_66028'
AND table_name = 'tbl';
  • table_schema is the name of your db
  • table_name the name of the table. If you omit this, you will query column information for all your tables.

See http://sqlfiddle.com/#!2/23f9b/1 for live demo. Here I used SELECT * for simplicity, but you will probably have to select only the require columns for your specific need.


In addition, MySQL is able to export query result as CSV file, a text format that Excel, like any other spreadsheet, might easily read. Something like that might do the trick:

SELECT * from information_schema.columns
WHERE table_schema = 'db_2_66028'
AND table_name = 'tbl'
INTO OUTFILE '/tmp/result.csv'
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
ESCAPED BY ‘\\’
LINES TERMINATED BY '\n'
like image 154
Sylvain Leroux Avatar answered Nov 02 '22 23:11

Sylvain Leroux