Skip to content
This repository has been archived by the owner on Nov 29, 2020. It is now read-only.

Commit

Permalink
reslove #23
Browse files Browse the repository at this point in the history
  • Loading branch information
tifayuki committed Aug 21, 2014
1 parent edf77b0 commit 724aa02
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 28 deletions.
8 changes: 4 additions & 4 deletions 5.5/import_sql.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash

if [[ $# -ne 2 ]]; then
echo "Usage: $0 <password> </path/to/sql_file.sql>"
if [[ $# -ne 3 ]]; then
echo "Usage: $0 <username> <password> </path/to/sql_file.sql>"
exit 1
fi

Expand All @@ -11,9 +11,9 @@ sleep 5
echo " Started with PID $!"

echo "=> Importing SQL file"
mysql -uadmin -p"$1" < "$2"
mysql -u"$1" -p"$2" < "$3"

echo "=> Stopping MySQL Server"
mysqladmin -uadmin -p"$1" shutdown
mysqladmin -u"$1" -p"$2" shutdown

echo "=> Done!"
8 changes: 4 additions & 4 deletions 5.6/import_sql.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash

if [[ $# -ne 2 ]]; then
echo "Usage: $0 <password> </path/to/sql_file.sql>"
if [[ $# -ne 3 ]]; then
echo "Usage: $0 <username> <password> </path/to/sql_file.sql>"
exit 1
fi

Expand All @@ -11,9 +11,9 @@ sleep 5
echo " Started with PID $!"

echo "=> Importing SQL file"
mysql -uadmin -p"$1" < "$2"
mysql -u"$1" -p"$2" < "$3"

echo "=> Stopping MySQL Server"
mysqladmin -uadmin -p"$1" shutdown
mysqladmin -u"$1" -p"$2" shutdown

echo "=> Done!"
40 changes: 20 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,36 +15,36 @@ Usage

To create the image `tutum/mysql`, execute the following command on the tutum-mysql folder:

docker build -t tutum/mysql 5.5/
docker build -t tutum/mysql 5.5/

To run the image and bind to port 3306:

docker run -d -p 3306:3306 tutum/mysql
docker run -d -p 3306:3306 tutum/mysql

The first time that you run your container, a new user `admin` with all privileges
will be created in MySQL with a random password. To get the password, check the logs
of the container by running:

docker logs <CONTAINER_ID>
docker logs <CONTAINER_ID>

You will see an output like the following:

========================================================================
You can now connect to this MySQL Server using:
========================================================================
You can now connect to this MySQL Server using:

mysql -uadmin -p47nnf4FweaKu -h<host> -P<port>
mysql -uadmin -p47nnf4FweaKu -h<host> -P<port>

Please remember to change the above password as soon as possible!
MySQL user 'root' has no password but only allows local connections
========================================================================
Please remember to change the above password as soon as possible!
MySQL user 'root' has no password but only allows local connections
========================================================================

In this case, `47nnf4FweaKu` is the password allocated to the `admin` user.

Remember that the `root` user has no password but it's only accesible from within the container.
Remember that the `root` user has no password but it's only accessible from within the container.

You can now test your deployment:

mysql -uadmin -p
mysql -uadmin -p

Done!

Expand All @@ -55,11 +55,11 @@ Setting a specific password for the admin account
If you want to use a preset password instead of a random generated one, you can
set the environment variable `MYSQL_PASS` to your specific password when running the container:

docker run -d -p 3306:3306 -e MYSQL_PASS="mypass" tutum/mysql
docker run -d -p 3306:3306 -e MYSQL_PASS="mypass" tutum/mysql

You can now test your deployment:

mysql -uadmin -p"mypass"
mysql -uadmin -p"mypass"

The admin username can also be set via the MYSQL_USER environment variable.

Expand All @@ -70,15 +70,15 @@ Mounting the database file volume
In order to persist the database data, you can mount a local folder from the host
on the container to store the database files. To do so:

docker run -d -v /path/in/host:/var/lib/mysql tutum/mysql /bin/bash -c "/usr/bin/mysql_install_db"
docker run -d -v /path/in/host:/var/lib/mysql tutum/mysql /bin/bash -c "/usr/bin/mysql_install_db"

This will mount the local folder `/path/in/host` inside the docker in `/var/lib/mysql` (where MySQL will store the database files by default). `mysql_install_db` creates the initial database structure.

Remember that this will mean that your host must have `/path/in/host` available when you run your docker image!

After this you can start your mysql image but this time using `/path/in/host` as the database folder:

docker run -d -p 3306:3306 -v /path/in/host:/var/lib/mysql tutum/mysql
docker run -d -p 3306:3306 -v /path/in/host:/var/lib/mysql tutum/mysql


Mounting the database file volume from other containers
Expand All @@ -104,17 +104,17 @@ In order to migrate your current MySQL server, perform the following commands fr

To dump your databases structure:

mysqldump -u<user> -p --opt -d -B <database name(s)> > /tmp/dbserver_schema.sql
mysqldump -u<user> -p --opt -d -B <database name(s)> > /tmp/dbserver_schema.sql

To dump your database data:

mysqldump -u<user> -p --quick --single-transaction -t -n -B <database name(s)> > /tmp/dbserver_data.sql
mysqldump -u<user> -p --quick --single-transaction -t -n -B <database name(s)> > /tmp/dbserver_data.sql

To import a SQL backup which is stored for example in the folder `/tmp` in the host, run the following:

sudo docker run -d -v /tmp:/tmp tutum/mysql /bin/bash -c "/import_sql.sh <rootpassword> /tmp/<dump.sql>")
sudo docker run -d -v /tmp:/tmp tutum/mysql /bin/bash -c "/import_sql.sh <user> <pass> /tmp/<dump.sql>"

Where `<rootpassword>` is the root password set earlier and `<dump.sql>` is the name of the SQL file to be imported.
Where `<user>` and `<pass>` are the database username and password set earlier and `<dump.sql>` is the name of the SQL file to be imported.


Environment variables
Expand All @@ -123,7 +123,7 @@ Environment variables
`MYSQL_USER`: Set a specific username for the admin account (default 'admin')
`MYSQL_PASS`: Set a specific password for the admin account.

Compatibliity Issues
Compatibiliity Issues
--------------------

- Volume created by MySQL 5.6 cannot be used in MySQL 5.5 Images or MariaDB images

0 comments on commit 724aa02

Please sign in to comment.