Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

mysql dump in excel format

by cynosure (Initiate)
on May 23, 2005 at 17:31 UTC ( [id://459634]=perlquestion: print w/replies, xml ) Need Help??

cynosure has asked for the wisdom of the Perl Monks concerning the following question:

Hello monks, I am new to perl. I want a dump of mysql database in excel/csv format. Can anyone please provide me with a script which can do this. anxiously waiting for your replies, Thanks for your help, Gaurav

Replies are listed 'Best First'.
Re: mysql dump in excel format
by jZed (Prior) on May 23, 2005 at 17:48 UTC
    I believe MySQL has a native dump mechanism that will dump to CSV (which Excel can read). If not, it's a six lines of code with DBD::CSV
    use DBI; my $mysql_dbh = DBI->connect( ... mysql_dsn); my $csv_dbh = DBI->connect( ... csv_dsn); my $mysql_sth = $mysql_dbh->prepare( ...mysql_select_sql); $mysql_sth->execute; $csv_dbh->do("CREATE TABLE excelsheet AS IMPORT(?)",{},$mysql_sth);
Re: mysql dump in excel format
by Tanktalus (Canon) on May 23, 2005 at 17:39 UTC

    Welcome to perlmonks! This is a wonderful place to discuss all things perl - including learning perl. However, it's a really poor place to have someone do your work for you. (In fact, most places are, at least the ones you don't pay for.) So the question is, what have you tried so far?

    I'll give you some hints to get you started, though: check out Text::CSV or Spreadsheet::WriteExcel for the writing part, and DBD::MySQL for the reading part.

Re: mysql dump in excel format
by Ninthwave (Chaplain) on May 23, 2005 at 18:58 UTC

    This is outside of perl but the MySQL query browser which is available from mysql.com has some export routines that will allow you to dump to csv, html, xml and xsl (though only Office XP compatible as it is the xml office format.) And you can do these dumps based on the query result set. Not bad if you need to visualise the data first and get the output quickly. I use the query browser to design the queries my scripts need. And get a visual feel of the data before I automate. The question is, does this need to be an automated process or is it just a dump and go. If it is dump and go use the query browser, if it is automated script check the examples given.

    "No matter where you go, there you are." BB
Re: mysql dump in excel format
by rlucas (Scribe) on May 23, 2005 at 22:35 UTC
    First, realize that the analog to a CSV file or Excel sheet is a single table, not a database. You'll need as many CSV files as you have tables to make sense of things, realistically.

    Second, just try using mysql from the command-line with -e'select * from table' and pipe to a file -- by default it will dump in TSV format, which Excel will open.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://459634]
Approved by Tanktalus
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (8)
As of 2024-04-23 13:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found