I am developing Rails v2.3 app. and using MySQL v5.1 .
I need to stop and start mysql database in one of my rake task, but I am not sure how to implement this thing, could some one help me?
namespace :db do
task :some_db_task => :environment do
#shut down mysql
...
#start mysql
end
end
By the way, I am developing on Ubuntu machine.
———————– update —————————-
I tried exec "/etc/init.d/mysql stop" , I got the following error message:
Rather than invoking init scripts through /etc/init.d, use the service(8)
utility, e.g. service mysql stop
Since the script you are attempting to invoke has been converted to an
Upstart job, you may also use the stop(8) utility, e.g. stop mysql
stop: Rejected send message, 1 matched rules; type="method_call", sender=":1.78" (uid=1000 pid=6331 comm="stop) interface="com.ubuntu.Upstart0_6.Job" member="Stop" error name="(unset)" requested_reply=0 destination="com.ubuntu.Upstart" (uid=0 pid=1 comm="/sbin/init"))
I tried /etc/init.d/mysql stop also on command line, the same error raise,
By following the error message’s instruction, I then tried service mysql stop , I got a new error message:
stop: Rejected send message, 1 matched rules; type="method_call", sender=":1.79" (uid=1000 pid=6343 comm="stop) interface="com.ubuntu.Upstart0_6.Job" member="Stop" error name="(unset)" requested_reply=0 destination="com.ubuntu.Upstart" (uid=0 pid=1 comm="/sbin/init"))
why I can not stop mysql??
————— update 2 ————————-
I realize that even though the above mentioned error message shows, the sudo /etc/init.d/mysql stop actually done its job. The MySQL get stopped by this command, meanwhile the message raising.
I’d prefer using system(“sudo /etc/init.d/mysqld stop”) so you can be sure the database has stoped. system() waits for the command to be executed while exec starts a background thread.
@update you may need “sudo service mysql stop” if you are using ubuntu lucid or newer