MySQL root 비밀번호를 까먹어서 지워버리고 새로운 마음으로 도커로 MySQL를 설치하고 사용하기로 했다!
💡 먼저 Docker가 설치되어있다는 전제하에
$ docker pull mysql:8.0.36
아래 명령어로 다운받은 이미지를 확인 할 수 있다
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mysql latest 3d6757ec48c5 13 days ago 638MB
redis 7-alpine 0be8a78a8b83 2 months ago 46.5MB
$ docker run --name mysql -e MYSQL_ROOT_PASSWORD=1234 -p 3306:3306 mysql:8.0.36
mysql
: 원하는 컨테이너 이름 작성
MYSQL_ROOT_PASSWORD=1234
: root 계정 비밀번호 설정
3306
:3306
: 외부포트:docker 내부포트 설정
8.0.36
: 원하는 MySQL버전
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
147ac55c1fe5 mysql "docker-entrypoint.s…" 3 hours ago Up 19 minutes 0.0.0.0:3306->3306/tcp, 33060/tcp mysql
컨테이너를 실행시킨 후 bash쉘에 접속한다
컨테이너 시작
$ docker start mysql
mysql
: 컨테이너 이름$ docker exec -it mysql bash
bash-4.4#
접속하면 위와같이 bash-4.4#
가 나올 것이다
bash-4.4# mysql -u root -p
Enter password:
mysql -u root -p
를 치면 위와 같이 비밀번호를 치라고 나오고 위에 설정해준 비밀번호를 치면
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.3.0 MySQL Community Server - GPL
Copyright (c) 2000, 2024, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
접속완료!
참고