Skip to content

Instantly share code, notes, and snippets.

@zeitounator
Last active May 25, 2020 11:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zeitounator/f2dc63883ed75d0f288aa980fd22526a to your computer and use it in GitHub Desktop.
Save zeitounator/f2dc63883ed75d0f288aa980fd22526a to your computer and use it in GitHub Desktop.
---------------------------------------------------
$ tree
.
├── docker-compose.yml
└── docker-entrypoint-initdb.d
└── init_my_db.sql
---------------------------------------------------
$ cat docker-entrypoint-initdb.d/init_my_db.sql
use pfmc;
create table test_table (id int not null auto_increment primary key, value varchar(255));
insert into test_table (value) values ('toto'), ('pipo'), ('bingo');
---------------------------------------------------
$ cat docker-compose.yml
version: "3.8"
services:
mysql:
image: mysql
command: --default-authentication-plugin=mysql_native_password
restart: always
volumes:
- pfmc-mysql-data:/var/lib/mysql
- ./docker-entrypoint-initdb.d:/docker-entrypoint-initdb.d
environment:
MYSQL_ROOT_PASSWORD: pfmc123
MYSQL_DATABASE: pfmc
volumes:
pfmc-mysql-data:
---------------------------------------------------
$ docker-compose up -d
Creating network "testdockermysql_default" with the default driver
Creating volume "testdockermysql_pfmc-mysql-data" with default driver
Creating testdockermysql_mysql_1 ... done
---------------------------------------------------
$ docker-compose logs mysql
Attaching to testdockermysql_mysql_1
mysql_1 | 2020-05-25 11:35:22+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.19-1debian9 started.
[... cut ...]
mysql_1 | 2020-05-25 11:35:39+00:00 [Note] [Entrypoint]: /usr/local/bin/docker-entrypoint.sh: running /docker-entrypoint-initdb.d/init_my_db.sql
[... cut ...]
| 2020-05-25T11:35:42.682839Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.19' socket: '/var/run/mysqld/mysqld.sock' port: 3306 MySQL Community Server - GPL.
mysql_1 | 2020-05-25T11:35:42.801586Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Socket: '/var/run/mysqld/mysqlx.sock' bind-address: '::' port: 33060
---------------------------------------------------
$ docker-compose exec mysql mysql -p -D pfmc -e "select * from test_table"
Enter password:
+----+-------+
| id | value |
+----+-------+
| 1 | toto |
| 2 | pipo |
| 3 | bingo |
+----+-------+
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment