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

To condense a very long story on how illogical things happened, is there any existing perl script or module that will enter a csv file (dump from a mysql db) back into a mysql db? Don't ask me how it happened, I don't know and don't want to know, but now I've got some huge csv files created from some sort of mysql dump. A search on google found no tools or documentation on how to reverse this.

Any ideas or suggestions? Thanks.

Replies are listed 'Best First'.
Re: CSV - Perl - MySQL ?
by Zaxo (Archbishop) on Jul 18, 2001 at 06:49 UTC

    The document you want is '$ info mysql'. No perl needed unless you need to automate this kind of recovery. Unfortunately, many mysql installations don't offer complete well-installed docs.

    mysql> LOAD DATA INFILE backup.csv INTO TABLE mytable; # there are opt +ions

    The above requires file permissions on the server. mysqlimport is available from the command line in that case. For its very complete usage screen, run without agruments.

    After Compline,
    Zaxo

Re: CSV - Perl - MySQL ?
by jepri (Parson) on Jul 18, 2001 at 06:41 UTC
    Heh. Was that you posting on the CLUG list a few hours ago? Around here we tend to answer specific questions better than vague ones. Part of the trouble with your question is that the answer is a simple 'yes'. Perl can do anything you want with data files.

    We've all written scripts to do similar things to what you want. I can show you one that I used to load data into a PostGre database, but it won't help you because the data is different.

    You will either have to post your scehma or start to write a program, which we can then help you with.

    ____________________
    Jeremy
    I didn't believe in evil until I dated it.

Re: CSV - Perl - MySQL ?
by Albannach (Monsignor) on Jul 18, 2001 at 06:50 UTC
    You might want to check out DBD::AnyData. Though it is quite new and I haven't tried the particular task you've got, it looks very promising for this sort of thing and it's worked well for me in my limited tests handling CSV data.

    Update: Well it's early days still, but I read the docs some more and found that the very cool DBD::AnyData ad_convert command can't use a DBI target yet. Perhaps with the SQL capabilities?

    --
    I'd like to be able to assign to an luser