0

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.

1
  • What if you issue mysqld shutdown immediately after? Commented Sep 28, 2013 at 11:54

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.