Skip to content

Commit ad7cb7d

Browse files
committed
Added MySQL 8 example
1 parent 7ef3688 commit ad7cb7d

File tree

3 files changed

+205
-0
lines changed

3 files changed

+205
-0
lines changed

mysql/README.md

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Run
2+
```shell
3+
docker-compose up -d
4+
```
5+
6+
# Stop
7+
```shell
8+
docker-compose down
9+
```
10+
11+
# Logs
12+
```shell
13+
docker compose logs
14+
```
15+
16+
# Connection string
17+
`jdbc:mysql://localhost:3306/sandbox`
18+
19+
# Query
20+
```sql
21+
SELECT `course_name`, ROUND(SUM(cnt) / COUNT(`month`), 2) `avg_months`
22+
FROM (SELECT `course_name`, month (`subscription_date`) `month`, COUNT(*) cnt
23+
FROM `PurchaseList`
24+
WHERE YEAR (`subscription_date`) = 2018
25+
GROUP by `course_name`, month (`subscription_date`)) t
26+
GROUP by `course_name`
27+
ORDER BY `avg_months` desc
28+
```

mysql/docker-compose.yml

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
version: '3'
2+
3+
services:
4+
db:
5+
container_name: mysql_8
6+
restart: always
7+
image: mysql:8.0.35-oracle
8+
command: mysqld --default-authentication-plugin=mysql_native_password --character-set-server=utf8 --collation-server=utf8_unicode_ci
9+
environment:
10+
MYSQL_ROOT_PASSWORD: root
11+
MYSQL_DATABASE: sandbox
12+
# MYSQL_USER: sandbox_user
13+
# MYSQL_PASSWORD: passpass
14+
# MYSQL_ALLOW_EMPTY_PASSWORD: "yes"
15+
ports:
16+
- '3306:3306'
17+
volumes:
18+
- './docker/db/data:/var/lib/mysql'
19+
# - './docker/db/my.cnf:/etc/mysql/conf.d/my.cnf'
20+
- './docker/db/sql:/docker-entrypoint-initdb.d'

0 commit comments

Comments
 (0)