목표 : mysql 서버를 다운받고 이것저것 작업해본다
어디서 : 우분투, cmd 등에서
어떻게 : 리눅스 명령어를 입력해서
1. MySQL 서버 다운(진한글씨만 입력하는 부분)
- weare@DESKTOP-BE1I4GE:~$ docker pull mysql/mysql-server:8.0
8.0: Pulling from mysql/mysql-server
6a4a3ef82cdc: Pull complete
5518b09b1089: Pull complete
b6b576315b62: Pull complete
349b52643cc3: Pull complete
abe8d2406c31: Pull complete
c7668948e14a: Pull complete
c7e93886e496: Pull complete
Digest: sha256:d6c8301b7834c5b9c2b733b10b7e630f441af7bc917c74dba379f24eeeb6a313
Status: Downloaded newer image for mysql/mysql-server:8.0
docker.io/mysql/mysql-server:8.0
2. 다운받은 이미지(mysql 서버)를 docker 컨테이너 내에서 실행
- weare@DESKTOP-BE1I4GE:~$ docker run --name=mysql_container mysql/mysql-server:8.0
[Entrypoint] MySQL Docker Image 8.0.32-1.2.11-server
[Entrypoint] No password option specified for new database.
[Entrypoint] A random onetime password will be generated.
[Entrypoint] Initializing database
2023-12-24T04:29:20.955914Z 0 [Warning] [MY-011068] [Server] The syntax '--skip-host-cache' is deprecated and will be removed in a future release. Please use SET GLOBAL host_cache_size=0 instead.
2023-12-24T04:29:20.956019Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.32) initializing of server in progress as process 18
2023-12-24T04:29:20.976964Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2023-12-24T04:29:22.388125Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2023-12-24T04:29:26.271228Z 6 [Warning] [MY-010453] [Server] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
[Entrypoint] Database initialized
2023-12-24T04:29:34.688538Z 0 [Warning] [MY-011068] [Server] The syntax '--skip-host-cache' is deprecated and will be removed in a future release. Please use SET GLOBAL host_cache_size=0 instead.
2023-12-24T04:29:34.689584Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.32) starting as process 61
2023-12-24T04:29:34.707921Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2023-12-24T04:29:34.995939Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2023-12-24T04:29:35.466111Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2023-12-24T04:29:35.466167Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
2023-12-24T04:29:35.491364Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Socket: /var/run/mysqld/mysqlx.sock
2023-12-24T04:29:35.491546Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.32' socket: '/var/lib/mysql/mysql.sock' port: 0 MySQL Community Server - GPL.
Warning: Unable to load '/usr/share/zoneinfo/iso3166.tab' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/leapseconds' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/tzdata.zi' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/zone.tab' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/zone1970.tab' as time zone. Skipping it.
[Entrypoint] GENERATED ROOT PASSWORD: +4ua5uBgh#vIo=8?;?88JCueH/q61o0/
[Entrypoint] ignoring /docker-entrypoint-initdb.d/*
2023-12-24T04:29:37.735110Z 11 [System] [MY-013172] [Server] Received SHUTDOWN from user root. Shutting down mysqld (Version: 8.0.32).
2023-12-24T04:29:41.845476Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.32) MySQL Community Server - GPL.
[Entrypoint] Server shut down
[Entrypoint] Setting root user as expired. Password will need to be changed before database can be used.
[Entrypoint] MySQL init process done. Ready for start up.
[Entrypoint] Starting MySQL 8.0.32-1.2.11-server
2023-12-24T04:29:42.927093Z 0 [Warning] [MY-011068] [Server] The syntax '--skip-host-cache' is deprecated and will be removed in a future release. Please use SET GLOBAL host_cache_size=0 instead.
2023-12-24T04:29:42.928040Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.32) starting as process 1
2023-12-24T04:29:42.933698Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2023-12-24T04:29:43.129131Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2023-12-24T04:29:43.386345Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2023-12-24T04:29:43.386395Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
2023-12-24T04:29:43.436052Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060, socket: /var/run/mysqld/mysqlx.sock
2023-12-24T04:29:43.436145Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.32' socket: '/var/lib/mysql/mysql.sock' port: 3306 MySQL Community Server - GPL.
- 정상 실행 중 -> 터미널 따로 하나 열어야함
3. mysql root의 비밀번호 찾아보기
- MySQL 컨테이너의 로그에서 표준에러(2)를 표준 출력(1)으로 가져오고, 이를 다시 grep GENERATED 명령어로 전달하여 "GENERATED" 라는 문자열이 포함된 라인을 찾습니다.
weare@DESKTOP-BE1I4GE:~$ docker logs mysql_container 2>&1|grep GENERATED
[Entrypoint] GENERATED ROOT PASSWORD: +4ua5uBgh#vIo=8?;?88JCueH/q61o0/
+A | B : A명령어를 B에 전달
+ & : 리다이렉트하는 역할
4. 구한 비밀번호 이용해서 mysql shell 열어보기
- weare@DESKTOP-BE1I4GE:~$ docker exec -it mysql_container mysql -uroot -p
- it : Docker 컨테이너를 interactive(대화형) 모드로 실행하고 터미널에 연결할 때 사용
- docker exec: 이 명령은 실행 중인 컨테이너 내에서 명령을 실행할 수 있게 합니다.
- -it: 이 옵션들은 대화형 터미널을 사용하여 명령을 실행할 수 있게 합니다.
- mysql_container: 이는 명령을 실행할 MySQL 컨테이너의 이름입니다.
- mysql -uroot -p: 이는 MySQL 명령행 클라이언트 명령입니다. 지정된 사용자 (-uroot는 root 사용자를 나타냄)로 MySQL 서버에 연결하고 비밀번호를 입력하도록 요청합니다.
-p 는 비밀번호를 요청
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 24
Server version: 8.0.32
Copyright (c) 2000, 2023, 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>
5. 임시비밀번호에서 원하는 비밀번호로 변경
- mysql> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql> alter USER root@localhost IDENTIFIED BY '새비밀번호';
Query OK, 0 rows affected (0.02 sec)
6. 데이터 베이스 구경
- 데이터 베이스가 4개 저장돼있는것 확인
mysql> show databases
-> exit
-> show databases;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'exit
show databases' at line 2
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.01 sec)
- 데이터 베이스 mysql로 선택
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
- mysql 내부 테이블 보기
mysql> show tables;
+------------------------------------------------------+
| Tables_in_mysql |
+------------------------------------------------------+
| columns_priv |
| component |
| db |
| default_roles |
| engine_cost |
| func |
| general_log |
| global_grants |
| gtid_executed |
| help_category |
| help_keyword |
| help_relation |
| help_topic |
| innodb_index_stats |
| innodb_table_stats |
| ndb_binlog_index |
| password_history |
| plugin |
| procs_priv |
| proxies_priv |
| replication_asynchronous_connection_failover |
| replication_asynchronous_connection_failover_managed |
| replication_group_configuration_version |
| replication_group_member_actions |
| role_edges |
| server_cost |
| servers |
| slave_master_info |
| slave_relay_log_info |
| slave_worker_info |
| slow_log |
| tables_priv |
| time_zone |
| time_zone_leap_second |
| time_zone_name |
| time_zone_transition |
| time_zone_transition_type |
| user |
+------------------------------------------------------+
38 rows in set (0.00 sec)
7. 사용한 명령어 몇개 살펴보기
docker run --name : 사용하기 편한 컨테이너 아이디 지정
docker logs : container쪽에서 생성된 stdout, stderr단의 로그를 읽어옴, --follow 사용시 로그 계속적으로 스트리밍됨