#TIL #mysql #docker MySQL 초기화가 끝나고 연결 가능한 상태인지 확인하기
$ docker run \
> --name mysql-temp \
> -e MYSQL_ROOT_PASSWORD=supersecret \
> -d \
> --rm \
> -p 3310:3306 \
> mysql:5.7.23
-d
옵션을 사용해 백그라운드로 실행하는 mysql docker 컨테이너를 만들었다. mysql 초기화가 다 끝나고 명령을 받을 준비가 됐다는 걸 어떻게 확인할 수 있을까?
$ while ! mysqladmin ping -hlocalhost -uroot -psupersecret -P3310; do
> sleep 1
> done
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
mysqladmin: connect to server at 'localhost' failed
error: 'Lost connection to MySQL server at 'reading initial communication packet', system error: 0'
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
mysqladmin: connect to server at 'localhost' failed
error: 'Lost connection to MySQL server at 'reading initial communication packet', system error: 0'
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
mysqladmin: connect to server at 'localhost' failed
error: 'Lost connection to MySQL server at 'reading initial communication packet', system error: 0'
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
mysqladmin: connect to server at 'localhost' failed
error: 'Lost connection to MySQL server at 'reading initial communication packet', system error: 0'
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
mysqld is alive
mysqladmin 프로그램의 ping 명령을 사용하면 된다. 에러 메시지를 안 찍는 -s 옵션도 있다.