Last active
September 1, 2015 06:50
-
-
Save mistymagich/264955e652db26a8c240 to your computer and use it in GitHub Desktop.
Sample to running a custom SQL in "Docker Official MySQL Image"
This file contains hidden or 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
web: | |
image: corbinu/docker-phpmyadmin | |
ports: | |
- "80:80" | |
links: | |
- mysql:mysql | |
environment: | |
MYSQL_USERNAME: root | |
mysql: | |
image: mysql | |
volumes: | |
- ./initdb.d:/docker-entrypoint-initdb.d | |
environment: | |
MYSQL_ROOT_PASSWORD: mysqlpassword | |
MYSQL_USER: "example_user" | |
MYSQL_PASSWORD: "example_pass" | |
MYSQL_DATABASE: "example" | |
ports: | |
- "3306:3306" |
This file contains hidden or 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 -eu | |
mysql=( mysql --protocol=socket -uroot -p"${MYSQL_ROOT_PASSWORD}" ) | |
"${mysql[@]}" <<-EOSQL | |
CREATE DATABASE IF NOT EXISTS another_db; | |
GRANT ALL ON another_db.* TO '${MYSQL_USER}'@'%' ; | |
EOSQL |
This file contains hidden or 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
CREATE TABLE IF NOT EXISTS `example`.`sample` ( | |
`id` INT UNSIGNED NOT NULL, | |
`name` VARCHAR(255) NOT NULL, | |
`created_at` DATETIME NOT NULL, | |
PRIMARY KEY (`id`)) | |
ENGINE = InnoDB; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment