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

Hi All Wise One's :)

This is a rather basic perl/mysql question but I have searched and searched without finding an answer. I am faced with the following problem:

I have a perl script that I was to use to connect to a mysql database and print a backup to the screen, exactly what mysqldump does but I don't want to involve system files or directories - so get a backup from perl and print it directly.

Is this possible? I have viewed the mysql docs to see if I culd return a dump like output with a query but all I could find was SELECT INTO FILE.

Thanks

Replies are listed 'Best First'.
Re: MySQL backup without MySQLDump
by cchampion (Curate) on Oct 25, 2003 at 20:06 UTC
Re: MySQL backup without MySQLDump
by jonadab (Parson) on Oct 25, 2003 at 20:06 UTC

    I don't know what MySQLDump does, but there are two basic approaches to backing up your database:

    • Back it up as one big opaque chunk of data. This is the easy way. All you do is get a read lock and copy or tar up the directories where MySQL stores the database. The read lock prevents any changes from going into the database while you're making the backup, so you get a consistent state. Anything that was trying to make changes is just delayed until you release the lock. This is the approach I use for backing up my databases. I'm not sure what you mean by "I don't want to involve system files or directories", but the only files or directories involved are the ones where MySQL stores your data, which to my way of thinking are application files and directories (MySQL ones in particular), not system ones. But if by "system files or directories" you mean that you don't want to involve the filesystem at all (why?) then this approach isn't for you.
    • The other way is to loop through all the records in all the tables and back them up individually. This is the more brittle approach in some ways because you'll have to change your backup script any time any of your tables change. But it should work. Just make a list of all your tables, do a foreach loop over them, and for each one SELECT * FROM tablename, and store complete copies of all the returned rows.

    $;=sub{$/};@;=map{my($a,$b)=($_,$;);$;=sub{$a.$b->()}} split//,".rekcah lreP rehtona tsuJ";$\=$ ;->();print$/

      I don't know what MySQLDump does...

      From the doc:

      Utility to dump a database or a collection of database for backup or for transferring the data to another SQL server (not necessarily a MySQL server). The dump will contain SQL statements to create the table and/or populate the table.
      -- vek --
Re: MySQL backup without MySQLDump
by vek (Prior) on Oct 25, 2003 at 22:30 UTC
    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: MySQL backup without MySQLDump
by reclaw (Curate) on Oct 25, 2003 at 20:22 UTC
    I think you could convert to CSV, Fixed or even an HTML table using DBD::AnyData and print it.

    Reclaw

    Your mileage may very.