Skip to content

Instantly share code, notes, and snippets.

@wcxaaa
Last active February 22, 2018 03:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wcxaaa/72a5a3fe12878c4bb3ec496c5ce8d668 to your computer and use it in GitHub Desktop.
Save wcxaaa/72a5a3fe12878c4bb3ec496c5ce8d668 to your computer and use it in GitHub Desktop.
Initializing docker mysql-server container
$ docker run --name mysql-c1 -d -v /workspace/docking:/workspace/docking mysql/mysql-server

Remember to wait for a few seconds and then continue.

$ docker logs mysql-c1 2>&1 | grep GENERATED # On Windows it's "findstr" instead of "grep"
# Copy that password from output: e.g. GENERATED ROOT PASSWORD: Axegh3kAJyDLaRuBemecis&EShOs
$ docker exec -it mysql-c1 mysql -u root -p
# [Enter Password]
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'newpassword';
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'newpassword' WITH GRANT OPTION;

- e.g. Create WordPress DB
mysql> CREATE DATABASE gourmet CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
mysql> exit
# After exiting to host machine, you may inspect the container id.
$ docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' mysql-c1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment