외부접속 설정
생성한 데이터베이스 클릭 -> VPC 보안그룹 -> 아래부분에서 인바운드 규칙 편집
보안 추가 IPv4 MYSQL/Aurora
필자는 MySQL의 커맨드를 사용해서 이전까지는 시스템환경변수 설정이 불필요했다. 외부접속을 위해서 환경변수를 설정해주었다.
MySQL 서버파일의 경로를 복사
시스템 환경 변수 -> 환경변수
Path클릭 후 편집 -> 새로 만들기 -> 복사한 주소 추가
실행확인
외부접속 실행
%mysql -h <엔드포인트> -P <포트> -u <유저명> -p
(base) PS C:\Users\HPcom> mysql -h "Your_End_Point" -P Your_Port_number -u Your_User_Name -p
Enter password: *********
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 20
Server version: 8.0.32 Source distribution
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> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.04 sec)
mysql> use mysql
Database changed
mysql> select host, user from user;
+-----------+------------------+
| host | user |
+-----------+------------------+
| % | admin |
| localhost | mysql.infoschema |
| localhost | mysql.session |
| localhost | mysql.sys |
| localhost | rdsadmin |
+-----------+------------------+
5 rows in set (0.04 sec)
test01.sql
CREATE TABLE police_station ( name varchar(16), address varchar(128) );
test02.sql
CREATE TABLE crime_status ( year YEAR, police_station VARCHAR(8), crime_type VARCHAR(16), status_type CHAR(2), case_number int );
로그인 후 SQL File 실행
해당 폴더 위치로 이동 후 SQL 로그인
이동 : cd <path>
로그인 : mysql -u root -p <datbase>
파일 실행 : source test01.sql
PS C:\Users\HPcom\Documents\sql_ws> mysql -u root -p zerobase Enter password: ******** Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 25 Server version: 8.0.32 MySQL Community Server - GPL Copyright (c) 2000, 2023, Oracle and/or its affiliates. Oracle is a registered trademark of Oracle Corporation and/or its owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> source test01.sql Query OK, 0 rows affected (0.03 sec) +--------------------+ | Tables_in_zerobase | +--------------------+ | celeb | | police_station | | snl_show | | test1 | +--------------------+ 5 rows in set (0.00 sec)
외부에서 바로 실행
이동 : cd <path>
로그인 및 실행 : mysql -u root -p <datbase> < <sqlfile>
mysql> exit Bye C:\Users\HPcom\Documents\sql_ws>mysql -u root -p zerobase < test02.sql Enter password: ******** C:\Users\HPcom\Documents\sql_ws>mysql -u root -p zerobase Enter password: ******** Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 27 Server version: 8.0.32 MySQL Community Server - GPL 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> use zerobase; Database changed mysql> show tables; +--------------------+ | Tables_in_zerobase | +--------------------+ | celeb | | crime_status | | police_station | | snl_show | | test1 | | test2 | +--------------------+ 6 rows in set (0.00 sec)
특정 데이터베이스 백업
mysqldump -u username -p dbname > backup.sql
모든 데이터베이스 백업
mysqldump -u username -p --all-databases > backup.sql
테이블 단위 백업
mysqldump -u username -p dbname tablename > backup.sql
데이터를 제외하고 스키마(구조)만 백업
mysqldump -d -u username -p dbname > backup.sql
mysqldump -d -u username -p --all-databases > backup.sql
mysqldump -d -u username -p dbname tablename > backup.sql
백업데이터 불러오기
source backup.sql
Local DB:zerobase 데이터 백업하기
- cmd에서 백업하기
C:\Users\HPcom\Documents\sql_ws>mysqldump -u root -p zerobase > zerobase_backup.sql Enter password: ********
AWS RDS에 Local DB:zerobase의 데이터 옮기기
- AWS RDS에 외부접속 후 백업데이터 실행
C:\Users\HPcom\Documents\sql_ws>mysql -h "database-1.cgto2ofp2xtq.ap-northeast-1.rds.amazonaws.com" -P 3306 -u admin -p Enter password: ********* Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 10 Server version: 8.0.32 Source distribution 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> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | sys | | zerobase | +--------------------+ 5 rows in set (0.05 sec) mysql> use zerobase Database changed mysql> show tables; Empty set (0.04 sec) mysql> source zerobase_backup.sql Query OK, 0 rows affected (0.04 sec) ...........중략........... Query OK, 0 rows affected (0.04 sec) mysql> show tables; +--------------------+ | Tables_in_zerobase | +--------------------+ | celeb | | crime_status | | police_station | | snl_show | | test1 | | test2 | +--------------------+ 6 rows in set (0.05 sec)
chcp 65001 입력 전
mysql> select * from police_station; +--------------------------------+--------------------------------------------+ | name | address | +--------------------------------+--------------------------------------------+ | ?쒖슱?밸퀎?쒓꼍李곗껌 | ?쒖슱??醫낅줈援??ъ쭅濡?湲?31 | | ?쒖슱以묐?寃쎌같? | ?쒖슱?밸퀎??以묎뎄 ?섑몴濡?27 | | ?쒖슱醫낅줈寃쎌같? | ?쒖슱?밸퀎??醫낅줈援??④끝濡?46 | | ?쒖슱?⑤?臾멸꼍李곗꽌 | ?쒖슱?밸퀎??以묎뎄 ?쒓컯??줈 410 | +--------------------------------+--------------------------------------------+ 4 rows in set (0.04 sec)
chcp 65001 입력 후
mysql> select * from police_station; +--------------------------+-----------------------------------------+ | name | address | +--------------------------+-----------------------------------------+ | 서울특별시경찰청 | 서울시 종로구 사직로8길 31 | | 서울중부경찰서 | 서울특별시 중구 수표로 27 | | 서울종로경찰서 | 서울특별시 종로구 율곡로 46 | | 서울남대문경찰서 | 서울특별시 중구 한강대로 410 | +--------------------------+-----------------------------------------+ 4 rows in set (0.05 sec)