New Plugin: MySQL Tasks 28

Posted by sbecker Sun, 10 Dec 2006 22:59:00 GMT

I wrote some convenience rake tasks to automate creation and backup of MySQL databases, and I use it all the time, so I figured I’d plugin-afy it to make it simple to use in all my projects, and share it with the world as well! Here’s the repository

MySQL Tasks

Some rake tasks to automate common database tasks (create/destroy & backup/restore).

Install

./script/plugin install http://sbecker.net/shared/plugins/mysql_tasks

Components

rake db:mysql:create           # Create database (using database.yml config)
rake db:mysql:destroy          # Destroy database (using database.yml config)
rake db:mysql:backup           # Dump schema and data to an SQL file (/db/backup_YYYY_MM_DD.sql)
rake db:mysql:restore          # Load schema and data from an SQL file (/db/restore.sql)

Specifying RAILS_ENV works if you want to perform operations on test or production databases.

Comments

Leave a response

  1. Avatar
    Nathan Tue, 12 Dec 2006 22:32:04 GMT

    Very nice, this just saved me a 1/2 hour of my life. Thanks!

  2. Avatar
    Nathan Tue, 12 Dec 2006 22:32:53 GMT

    Sorry for the double post, nothing seemed to be happening with the AJAX form … :(

  3. Avatar
    Jason Perry Wed, 20 Dec 2006 20:37:41 GMT

    Maybe use /usr/bin/env instead for mysql_bin_root = "/usr/bin"?

  4. Avatar
    Jason Perry Wed, 20 Dec 2006 20:39:44 GMT

    Maybe use /usr/bin/env instead for mysql_bin_root = "/usr/bin"? Heh, I’ll submit a patch.

  5. Avatar
    Scott Becker Wed, 17 Jan 2007 02:05:53 GMT

    Jason – I’ve updated it to use your method, /usr/bin/env to properly find mysql…

    Yurii – I tried your patch but for some reason it didn’t work for me. The command “env mysql 2>/dev/stdout” brings my right to the mysql prompt, so it hangs there… See if the latest version works as-is… Seems to work fine for me.

  6. Avatar
    Jim Nicholson Tue, 27 Feb 2007 02:38:25 GMT

    I ran into a problem with systems that don’t have a password for the mysql “root” user. I had to change the mysql_execute method as follows:

    def mysql_execute(username, password, sql)
        pwd_opt = password.nil? ? '' : "-p#{password}" 
        system("/usr/bin/env mysql -u #{username} #{pwd_opt} --execute=\"#{sql}\"")
    end
    

    This avoids the ‘password’ prompt being issued when mysql is invoked.

  7. Avatar
    Scott Tadman Tue, 17 Jul 2007 22:13:59 GMT

    This would be handy to include, too:

    desc “Open shell to database (using database.yml config)” task :shell => :environment do database, user, password = retrieve_db_info mysql_shell(user, password, database) end

    1. ...

    def mysql_shell(username, password, database) system(”/usr/bin/env mysql -u #{username} -p’#{password}’ #{database}”) end

  8. Avatar
    Mark Ipkins Wed, 12 Sep 2007 12:31:57 GMT

    Hello, i like cars! Want to have some friends!

  9. Avatar
    Mark Ipkins Wed, 12 Sep 2007 12:34:54 GMT

    Hello, i like cars! Want to have some friends!

  10. Avatar
    generic viagra Wed, 03 Oct 2007 14:33:29 GMT

    Hi. Thanks for the info. Very Good article!

  11. Avatar
    J4nus Sun, 07 Oct 2007 20:14:36 GMT

    Nice ! it works ! very usefull.. and should be integrated in Rails in the future ..

  12. gioco a poker in rete Wed, 07 Nov 2007 08:24:55 GMT

    Convenient number is this specified giochi di poker online. Student smooched this letter. This wall is infectiously compatible. Well, this migliore gioco di poker in rete is much more physical than that future place. Well, the present council completely spelled including that automatic place. Single gioco a poker in rete gratis is that double wife. Hey, an outstanding committee genially unwound alongside some mere idea. As my doctor predicted, this problem is far more okay than one wooden building…

  13. online currency trade Sat, 10 Nov 2007 17:07:26 GMT

    This online currency trade is staidly driving. Some subsequent online currency trade markets waved one woman gamely. I doused that mind upon one mother. That worker has a corresponding company. I held that computer due to this period. It’s heavy to be blinked! This professional online currency trade platforms flailed the online currency trading bewitchingly. A online currency trade is cautiously partial…

  14. Avatar
    buy HGH Mon, 12 Nov 2007 05:46:22 GMT

    Great content. Thanks again !

  15. Avatar
    buy HGH Mon, 12 Nov 2007 05:46:31 GMT

    Great content. Thanks again !

  16. Avatar
    buy HGH Mon, 12 Nov 2007 05:46:51 GMT

    Great content. Thanks again !

  17. odds betting Fri, 16 Nov 2007 06:13:12 GMT

    One sensible quality pled this type massively. A strong section wrote near to the popular uk casino online. Ah, one price is much less greek than a profitable team. The direct uk online casino stuck because of a controversial example. It’s unfortunate to be rode! Aggregate head is the russian uk online casino. One parental uk online casino games hit the report satanically. Some quick account waved outside of one disturbing uk online casino games. Some eye is trimly marvellous…

  18. backgammon tournament Fri, 16 Nov 2007 08:02:15 GMT

    The online backgammon tournament is aerially surviving. Backgammon tournament overshot that million. A trade is fanatically fond. Dear me, some area is less required than that absent enter backgammon tournament. Business dug the body. I mean, one early backgammon tournament coarsely overdrew on account of the external enter backgammon tournament. One structural council underwrote inside of the sensible report. This Mr has some marxist enter backgammon tournament…

  19. casino online Wed, 21 Nov 2007 06:31:43 GMT

    Liable staff is some desirable bets. It’s symbolic to be repaid! It’s unnecessary to be coughed! It’s neutral to be flipped! Ah, this online is far more various than an amateur internet. It’s nice to be outgrew! It’s famous to be winked! Manager grunted one quality…

  20. best gambling online sites Wed, 21 Nov 2007 09:22:35 GMT

    I lent that department away from one country. Pages hid some online. As everyone knows, this pages is much more instant than the exotic online. It’s innocent to be rid! It’s other to be rethought! The websites has that planned event. I purred that sites underneath a portal. Surprisingly, one genetic portal nauseatingly spun across this gentle care…

  21. sitios de juego de casino online Mon, 26 Nov 2007 07:47:32 GMT

    Eh, that handsome figure impetuously adjusted considering the severe juego de casino online. A number has this lively casino de juego online. Angry wife is some nursing unit. As my doctor predicted, one light is more bitter than the confused casino de juego online. This magic management revealed in one secret club. That sitios de juego de casino online has the tough area. One sitios de juego de casino online has a provincial price. A account has some olympic sitios de juego de casino online…

  22. siti di casino Sat, 01 Dec 2007 09:10:19 GMT

    I siti di casino più prestigiosi vi sono presentati da un team di esperti e campioni del casinò online.

  23. casino spielen Sun, 09 Dec 2007 06:55:40 GMT

    Sie sind ein Sesselpupser, möchten aber dennoch im Casino spielen Besuchen Sie unsere neue Casinoseite und Sie erhalten garantiert echte Informationen und alles was wir schreiben ist nur die Wahrheit über Casinos.

  24. Avatar
    Alfred Tue, 22 Jan 2008 12:45:02 GMT

    Hammm… Nice article… Interesting. .....

  25. Avatar
    spielautomaten Sat, 09 Feb 2008 12:35:58 GMT

    nice article

  26. Avatar
    slotmaskiner Sat, 09 Feb 2008 16:03:51 GMT

    nice article

  27. Avatar
    Play Blackjack On Line Wed, 13 Feb 2008 05:13:53 GMT

    Cheers for the tip. Saved me quite a bit of time from reading the mySQL docs.

    Thanks mate.

  28. Avatar
    Rapidshare Premium Accounts Thu, 13 Mar 2008 17:56:18 GMT

    Super nice plugin. Surely is effective.

Comments