Created
March 21, 2014 22:09
-
-
Save pda/9697520 to your computer and use it in GitHub Desktop.
Docker script to initialize MySQL database; auth from remote hosts.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Initialize MySQL database. | |
# ADD this file into the container via Dockerfile. | |
# Assuming you specify a VOLUME ["/var/lib/mysql"] or `-v /var/lib/mysql` on the `docker run` command… | |
# Once built, do e.g. `docker run your_image /path/to/docker-mysql-initialize.sh` | |
# Again, make sure MySQL is persisting data outside the container for this to have any effect. | |
set -e | |
set -x | |
# Start the MySQL daemon in the background. | |
/usr/sbin/mysqld & | |
mysql_pid=$! | |
until mysqladmin ping &>/dev/null; do | |
echo -n "."; sleep 0.2 | |
done | |
# Permit root login without password from outside container. | |
mysql -e "GRANT ALL ON *.* TO root@'%' IDENTIFIED BY '' WITH GRANT OPTION" | |
# Tell the MySQL daemon to shutdown. | |
mysqladmin shutdown | |
# Wait for the MySQL daemon to exit. | |
wait $mysql_pid |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment