Reputation: 121
I'm attempting to script the creation of a machine image that includes MySQL with some seed data.
I'm looking for a way to start the MySQL database engine, run a .sql
script to create the data, and then shutdown the engine. Is there a best way to do this?
It looks like I could use the --init-file
argument of mysqld
to launch mysql
and run the script, but how would I cause the database engine to shutdown after the script completes?
I'm on Ubuntu if it matters.
Upvotes: 0
Views: 201
Reputation: 9354
Just do these three commands in one script:
service mysql start
mysql -umyuser -pmypass < /path/to/your/startup.sql
service mysql stop
You may consider using skip-networking
in your /etc/mysql/my.cnf
file so that the database is not accidentally accessed by anyone else for the short perios when it's up and running. In which case add the --socket
argument to your mysql
client command.
Upvotes: 1