日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

java初始化数据报_java – 如何在Docker中初始化数据库后启动flyway

發(fā)布時間:2025/3/15 数据库 15 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java初始化数据报_java – 如何在Docker中初始化数据库后启动flyway 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

我有以下docker compose文件(docker-compose-dev.yml):

version: '3'

services:

my_sql_db:

image: percona:latest

container_name: my_sql_db

environment:

MysqL_ROOT_PASSWORD: password

MysqL_DATABASE: abhs

ports:

- "3306:3306"

migration:

image: Boxfuse/flyway:latest

container_name: flyway_migration

volumes:

- ./flyway_scripts/src/main/resources/db/migration:/flyway/sql

command: -url=jdbc:MysqL://my_sql_db:3306/abhs?useUnicode=true&characterEncoding=utf8&useSSL=false -user=root -password=password migrate

depends_on:

- my_sql_db

并遵循docker-compose.yml:

version: '3'

services:

migration:

image: Boxfuse/flyway:latest

container_name: flyway_migration

volumes:

- ./flyway_scripts/src/main/resources/db/migration:/flyway/sql

然后我執(zhí)行以下命令:

docker-compose -f docker-compose.yml -f docker-compose-dev.yml up

它導致錯誤:

在日志中我看到以下內(nèi)容:

my_sql_db | Initializing database

flyway_migration | Flyway Community Edition 5.1.4 by Boxfuse

flyway_migration |

my_sql_db | 2018-08-24T08:47:41.616694Z 0 [Warning] 'NO_ZERO_DATE','NO_ZERO_IN_DATE' and 'ERROR_FOR_DIVISION_BY_ZERO' sql modes should be used with strict mode. They will be merged with strict mode in a future release.

my_sql_db | 2018-08-24T08:47:41.616747Z 0 [Warning] 'NO_AUTO_CREATE_USER' sql mode was not set.

flyway_migration | ERROR:

flyway_migration | Unable to obtain connection from database (jdbc:MysqL://my_sql_db:3306/abhs?useUnicode=true&characterEncoding=utf8&useSSL=false) for user 'root': Could not connect to address=(host=my_sql_db)(port=3306)(type=master) : Connection refused (Connection refused)

flyway_migration | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

flyway_migration | sql State : 08

flyway_migration | Error Code : -1

flyway_migration | Message : Could not connect to address=(host=my_sql_db)(port=3306)(type=master) : Connection refused (Connection refused)

my_sql_db | 2018-08-24T08:47:43.024690Z 0 [Warning] InnoDB: New log files created,LSN=45790

flyway_migration |

my_sql_db | 2018-08-24T08:47:43.443625Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.

my_sql_db | 2018-08-24T08:47:43.588008Z 0 [Warning] No existing UUID has been found,so we assume that this is the first time that this server has been started. Generating a new UUID: 5dc59a4f-a77a-11e8-b6cb-0242ac130002.

my_sql_db | 2018-08-24T08:47:43.760654Z 0 [Warning] Gtid table is not ready to be used. Table 'MysqL.gtid_executed' cannot be opened.

my_sql_db | 2018-08-24T08:47:44.518107Z 0 [Warning] CA certificate ca.pem is self signed.

my_sql_db | 2018-08-24T08:47:44.925466Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.

my_sql_db | 2018-08-24T08:47:54.762213Z 1 [Warning] 'user' entry 'root@localhost' ignored in --skip-name-resolve mode.

my_sql_db | 2018-08-24T08:47:54.762517Z 1 [Warning] 'user' entry 'MysqL.session@localhost' ignored in --skip-name-resolve mode.

my_sql_db | 2018-08-24T08:47:54.762889Z 1 [Warning] 'user' entry 'MysqL.sys@localhost' ignored in --skip-name-resolve mode.

my_sql_db | 2018-08-24T08:47:54.763244Z 1 [Warning] 'db' entry 'performance_schema MysqL.session@localhost' ignored in --skip-name-resolve mode.

my_sql_db | 2018-08-24T08:47:54.763472Z 1 [Warning] 'db' entry 'sys MysqL.sys@localhost' ignored in --skip-name-resolve mode.

my_sql_db | 2018-08-24T08:47:54.763788Z 1 [Warning] 'proxies_priv' entry '@ root@localhost' ignored in --skip-name-resolve mode.

my_sql_db | 2018-08-24T08:47:54.763928Z 1 [Warning] 'tables_priv' entry 'user MysqL.session@localhost' ignored in --skip-name-resolve mode.

my_sql_db | 2018-08-24T08:47:54.764128Z 1 [Warning] 'tables_priv' entry 'sys_config MysqL.sys@localhost' ignored in --skip-name-resolve mode.

my_sql_db | Database initialized

my_sql_db | MysqL init process in progress...

my_sql_db | 2018-08-24T08:47:58.970290Z 0 [Warning] 'NO_ZERO_DATE','NO_ZERO_IN_DATE' and 'ERROR_FOR_DIVISION_BY_ZERO' sql modes should be used with strict mode. They will be merged with strict mode in a future release.

my_sql_db | 2018-08-24T08:47:58.970345Z 0 [Warning] 'NO_AUTO_CREATE_USER' sql mode was not set.

my_sql_db | 2018-08-24T08:47:58.974061Z 0 [Note] MysqLd (MysqLd 5.7.22-22) starting as process 58 ...

my_sql_db | 2018-08-24T08:47:58.999651Z 0 [Note] InnoDB: PUNCH HOLE support available

my_sql_db | 2018-08-24T08:47:58.999685Z 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins

my_sql_db | 2018-08-24T08:47:58.999689Z 0 [Note] InnoDB: Uses event mutexes

my_sql_db | 2018-08-24T08:47:58.999692Z 0 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier

my_sql_db | 2018-08-24T08:47:58.999695Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.8

my_sql_db | 2018-08-24T08:47:58.999698Z 0 [Note] InnoDB: Using Linux native AIO

my_sql_db | 2018-08-24T08:47:59.000153Z 0 [Note] InnoDB: Number of pools: 1

my_sql_db | 2018-08-24T08:47:59.000426Z 0 [Note] InnoDB: Using cpu crc32 instructions

my_sql_db | 2018-08-24T08:47:59.002306Z 0 [Note] InnoDB: Initializing buffer pool,total size = 128M,instances = 1,chunk size = 128M

my_sql_db | 2018-08-24T08:47:59.006893Z 0 [Note] InnoDB: Completed initialization of buffer pool

my_sql_db | 2018-08-24T08:47:59.013219Z 0 [Note] InnoDB: If the MysqLd execution user is authorized,page cleaner thread priority can be changed. See the man page of setpriority().

my_sql_db | 2018-08-24T08:47:59.024242Z 0 [Note] InnoDB: Crash recovery did not find the parallel doublewrite buffer at /var/lib/MysqL/xb_doublewrite

my_sql_db | 2018-08-24T08:47:59.026263Z 0 [Note] InnoDB: Highest supported file format is Barracuda.

my_sql_db | 2018-08-24T08:47:59.066469Z 0 [Note] InnoDB: Created parallel doublewrite buffer at /var/lib/MysqL/xb_doublewrite,size 3932160 bytes

my_sql_db | 2018-08-24T08:47:59.071752Z 0 [Note] InnoDB: Creating shared tablespace for temporary tables

my_sql_db | 2018-08-24T08:47:59.072052Z 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...

my_sql_db | 2018-08-24T08:47:59.422155Z 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.

my_sql_db | 2018-08-24T08:47:59.423325Z 0 [Note] InnoDB: 96 redo rollback segment(s) found. 96 redo rollback segment(s) are active.

my_sql_db | 2018-08-24T08:47:59.423376Z 0 [Note] InnoDB: 32 non-redo rollback segment(s) are active.

my_sql_db | 2018-08-24T08:47:59.423900Z 0 [Note] InnoDB: Waiting for purge to start

my_sql_db | 2018-08-24T08:47:59.474066Z 0 [Note] InnoDB: Percona XtraDB (http://www.percona.com) 5.7.22-22 started; log sequence number 2595255

my_sql_db | 2018-08-24T08:47:59.474647Z 0 [Note] Plugin 'FEDERATED' is disabled.

my_sql_db | 2018-08-24T08:47:59.499970Z 0 [Note] Found ca.pem,server-cert.pem and server-key.pem in data directory. Trying to enable SSL support using them.

my_sql_db | 2018-08-24T08:47:59.500004Z 0 [Note] Skipping generation of SSL certificates as certificate files are present in data directory.

my_sql_db | 2018-08-24T08:47:59.500382Z 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/MysqL/ib_buffer_pool

my_sql_db | 2018-08-24T08:47:59.501263Z 0 [Warning] CA certificate ca.pem is self signed.

my_sql_db | 2018-08-24T08:47:59.522151Z 0 [Note] Skipping generation of RSA key pair as key files are present in data directory.

my_sql_db | 2018-08-24T08:47:59.531657Z 0 [Note] InnoDB: Buffer pool(s) load completed at 180824 8:47:59

看起來flyway在數(shù)據(jù)庫初始化之前啟動,因此無法連接到數(shù)據(jù)庫,我看到下面的錯誤.

我該如何解決這個問題?

附:

我搜索了類似的問題,我發(fā)現(xiàn)了以下建議:https://github.com/vishnubob/wait-for-it但我是碼頭工人的新手,我不明白如何把它放入我的docker compose文件中

P.S.2

我試著將文件wait-fot-it.sh放在compose文件附近并執(zhí)行:

command: ["./wait-for-it.sh","MysqL:3306","--","-url=jdbc:MysqL://my_sql_db:3306/abhs?useUnicode=true&characterEncoding=utf8&useSSL=false -user=root -password=password migrate"]

但是我返回ERROR:無效的參數(shù):./ wait-for-it.sh

P.S.3

我試過“重復”主題的方法:

version: '3'

services:

my_sql_db:

image: percona:latest

container_name: my_sql_db

environment:

MysqL_ROOT_PASSWORD: password

MysqL_DATABASE: abhs

ports:

- "3306:3306"

healthcheck:

test: ["CMD","MysqLadmin","ping","-h","localhost"]

timeout: 20s

retries: 10

migration:

image: Boxfuse/flyway:latest

container_name: flyway_migration

volumes:

- ./flyway_scripts/src/main/resources/db/migration:/flyway/sql

command: -url=jdbc:MysqL://my_sql_db:3306/abhs?useUnicode=true&characterEncoding=utf8&useSSL=false -user=root -password=password migrate

depends_on:

my_sql_db:

condition: service_healthy

但我看到以下錯誤:

$docker-compose -f docker-compose.yml -f docker-compose-dev.yml up

The Compose file '.\docker-compose-dev.yml' is invalid because:

services.migration.depends_on contains an invalid type,it should be an array

P.S.4

對于那種方法,我看到以下錯誤:

version: '3'

services:

my_sql_db:

image: percona:latest

container_name: my_sql_db

environment:

MysqL_ROOT_PASSWORD: password

MysqL_DATABASE: abhs

ports:

- "3306:3306"

healthcheck:

test: ["CMD","localhost"]

timeout: 20s

retries: 10

migration:

image: Boxfuse/flyway:latest

container_name: flyway_migration

volumes:

- ./flyway_scripts/src/main/resources/db/migration:/flyway/sql

command: dockerize wait jdbc:MysqL://my_sql_db:3306 -url=jdbc:MysqL://my_sql_db:3306/abhs?useUnicode=true&characterEncoding=utf8&useSSL=false -user=root -password=password migrate

depends_on:

- my_sql_db

我看到以下錯誤:

flyway_migration | ERROR: Invalid argument: dockerize

UPDATE_1

wait-for-it.sh內(nèi)容:

#!/usr/bin/env bash

# Use this script to test if a given TCP host/port are available

cmdname=$(basename $0)

echoerr() { if [[ $QUIET -ne 1 ]]; then echo "$@" 1>&2; fi }

usage()

{

cat << USAGE >&2

Usage:

$cmdname host:port [-s] [-t timeout] [-- command args]

-h HOST | --host=HOST Host or IP under test

-p PORT | --port=PORT TCP port under test

Alternatively,you specify the host and port as host:port

-s | --strict Only execute subcommand if the test succeeds

-q | --quiet Don't output any status messages

-t TIMEOUT | --timeout=TIMEOUT

Timeout in seconds,zero for no timeout

-- COMMAND ARGS Execute command with args after the test finishes

USAGE

exit 1

}

wait_for()

{

if [[ $TIMEOUT -gt 0 ]]; then

echoerr "$cmdname: waiting $TIMEOUT seconds for $HOST:$PORT"

else

echoerr "$cmdname: waiting for $HOST:$PORT without a timeout"

fi

start_ts=$(date +%s)

while :

do

if [[ $ISBUSY -eq 1 ]]; then

nc -z $HOST $PORT

result=$?

else

(echo > /dev/tcp/$HOST/$PORT) >/dev/null 2>&1

result=$?

fi

if [[ $result -eq 0 ]]; then

end_ts=$(date +%s)

echoerr "$cmdname: $HOST:$PORT is available after $((end_ts - start_ts)) seconds"

break

fi

sleep 1

done

return $result

}

wait_for_wrapper()

{

# In order to support SIGINT during timeout: http://unix.stackexchange.com/a/57692

if [[ $QUIET -eq 1 ]]; then

timeout $BUSYTIMEFLAG $TIMEOUT $0 --quiet --child --host=$HOST --port=$PORT --timeout=$TIMEOUT &

else

timeout $BUSYTIMEFLAG $TIMEOUT $0 --child --host=$HOST --port=$PORT --timeout=$TIMEOUT &

fi

PID=$!

trap "kill -INT -$PID" INT

wait $PID

RESULT=$?

if [[ $RESULT -ne 0 ]]; then

echoerr "$cmdname: timeout occurred after waiting $TIMEOUT seconds for $HOST:$PORT"

fi

return $RESULT

}

# process arguments

while [[ $# -gt 0 ]]

do

case "$1" in

*:* )

hostport=(${1//:/ })

HOST=${hostport[0]}

PORT=${hostport[1]}

shift 1

;;

--child)

CHILD=1

shift 1

;;

-q | --quiet)

QUIET=1

shift 1

;;

-s | --strict)

STRICT=1

shift 1

;;

-h)

HOST="$2"

if [[ $HOST == "" ]]; then break; fi

shift 2

;;

--host=*)

HOST="${1#*=}"

shift 1

;;

-p)

PORT="$2"

if [[ $PORT == "" ]]; then break; fi

shift 2

;;

--port=*)

PORT="${1#*=}"

shift 1

;;

-t)

TIMEOUT="$2"

if [[ $TIMEOUT == "" ]]; then break; fi

shift 2

;;

--timeout=*)

TIMEOUT="${1#*=}"

shift 1

;;

--)

shift

CLI=("$@")

break

;;

--help)

usage

;;

*)

echoerr "Unknown argument: $1"

usage

;;

esac

done

if [[ "$HOST" == "" || "$PORT" == "" ]]; then

echoerr "Error: you need to provide a host and port to test."

usage

fi

TIMEOUT=${TIMEOUT:-15}

STRICT=${STRICT:-0}

CHILD=${CHILD:-0}

QUIET=${QUIET:-0}

# check to see if timeout is from busyBox?

# check to see if timeout is from busyBox?

TIMEOUT_PATH=$(realpath $(which timeout))

if [[ $TIMEOUT_PATH =~ "busyBox" ]]; then

ISBUSY=1

BUSYTIMEFLAG="-t"

else

ISBUSY=0

BUSYTIMEFLAG=""

fi

if [[ $CHILD -gt 0 ]]; then

wait_for

RESULT=$?

exit $RESULT

else

if [[ $TIMEOUT -gt 0 ]]; then

wait_for_wrapper

RESULT=$?

else

wait_for

RESULT=$?

fi

fi

if [[ $CLI != "" ]]; then

if [[ $RESULT -ne 0 && $STRICT -eq 1 ]]; then

echoerr "$cmdname: strict mode,refusing to execute subprocess"

exit $RESULT

fi

exec "${CLI[@]}"

else

exit $RESULT

fi

P.S.5

我也試過這個:

version: '3'

services:

my_sql_db:

image: percona:latest

container_name: my_sql_db

environment:

MysqL_ROOT_PASSWORD: password

MysqL_DATABASE: abhs

ports:

- "3306:3306"

healthcheck:

test: ["CMD","localhost"]

timeout: 20s

retries: 10

migration:

image: Boxfuse/flyway:latest

container_name: flyway_migration

volumes:

- ./flyway_scripts/src/main/resources/db/migration:/flyway/sql

entrypoint: ["wait-for-it.sh","docker-entrypoint.sh"]

command: -url=jdbc:MysqL://my_sql_db:3306/abhs?useUnicode=true&characterEncoding=utf8&useSSL=false -user=root -password=password migrate

depends_on:

- my_sql_db

它會導致錯誤:

創(chuàng)建flyway_migration …錯誤

ERROR: for flyway_migration Cannot start service migration: OCI runtime create Failed: container_linux.go:348: starting container process caused "exec: \"wait-for-it.sh\": executable file not found in $PATH": unknown

ERROR: for migration Cannot start service migration: OCI runtime create Failed: container_linux.go:348: starting container process caused "exec: \"wait-for-it.sh\": executable file not found in $PATH": unknown

Encountered errors while bringing up the project.

總結(jié)

以上是生活随笔為你收集整理的java初始化数据报_java – 如何在Docker中初始化数据库后启动flyway的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。