New Plugin: MySQL Tasks 13
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_tasksComponents
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.
Very nice, this just saved me a 1/2 hour of my life. Thanks!
Sorry for the double post, nothing seemed to be happening with the AJAX form … :(
Maybe use
/usr/bin/envinstead formysql_bin_root = "/usr/bin"?Maybe use
/usr/bin/envinstead formysql_bin_root = "/usr/bin"? Heh, I’ll submit a patch.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.
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}\"") endThis avoids the ‘password’ prompt being issued when mysql is invoked.
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
def mysql_shell(username, password, database) system(”/usr/bin/env mysql -u #{username} -p’#{password}’ #{database}”) end
Hello, i like cars! Want to have some friends!
Hello, i like cars! Want to have some friends!
Nice ! it works ! very usefull.. and should be integrated in Rails in the future ..
Cheers for the tip. Saved me quite a bit of time from reading the mySQL docs.
Thanks mate.
I incorporated Jim’s change as well as a change to the restore tasks in order to support databases without a password.
http://github.com/eichert12/mysql_tasks/tree/master
Probably should kill the create/destroy tasks as well since they’re now in Rails.
メル友ソナタ♪ 無料出会いサイト テレクラ 出会い系エッチサイト宅急便!! 出会い系サイトDating 出会い 出会い 出会い 出会い 出会い 出会い 出会い 出会い 出会い 出会い 出会い 出会い 出会い 出会い 出会い 出会い 出会い 出会い 出会い 出会い 出会い 出会い 出会い 出会い 出会い 出会い 出会い 出会い 出会い 出会い 出会い 出会い 出会い 出会い 出会い 出会い 出会い 出会い 出会い 出会い 出会い 出会い 出会い 出会い 出会い 出会い