Reputation: 63546
In my deployment script, I run a script to set up my database after I run mysqld_safe
. But when the database setup runs, there is no mysql
process running yet. How can I make sure to run the database setup script only after the mysql
process is running?
Here's the script:
mysqld_safe >/tmp/spot.mysql.out 2>/tmp/spot.mysql.err &
mysql -u root < setup.sql
Upvotes: 0
Views: 608
Reputation: 2348
There are ways. If you have pidof
on your system (check with which pidof
), then you could use:
mysqld_safe >/tmp/spot.mysql.out 2>/tmp/spot.mysql.err &
while ! pidof mysql > /dev/null
do
sleep 5
done
mysql -u root < setup.sql
I don't know exactly how long you need mysqld_safe
to run, but, the way you have it start, it will probably die due to a SIGHUP
when your shell exits. To avoid that, make it ignore SIGHUP:
nohup mysqld_safe >/tmp/spot.mysql.out 2>/tmp/spot.mysql.err &
while ! pidof mysql > /dev/null
do
sleep 5
done
mysql -u root < setup.sql
Upvotes: 1