부록. MySQL 설치 및 세팅(윈도우 11 기준)
1. MySQL 설치
다음 페이지에서 설치 파일 다운로드
https://dev.mysql.com/downloads/windows/installer/8.0.html
설치 옵션에서 custom으로 다음 항목을 골라 설치 완료
2. 환경 세팅
cmd에서 mysql 클라이언트를 바로 실행하기 위한 시스템 환경 변수 편집
설정에서 변수 검색
환경 변수 클릭
시스템 변수에서 Path 선택 후 편집 클릭
새로 만들기 클릭
해당 경로 등록
C:\Program Files\MySQL\MySQL Server 8.0\bin
다음과 같이 확인 가능
C:\Users>mysql -uroot -p0000
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 19
Server version: 8.0.35 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.
3. 예제용 데이터베이스 구축
책에는 생략되어 있으나 데이터베이스 먼저 생성 필요
mysql> CREATE DATABASE sample
데이터베이스 생성 확인(sample이 존재해야 함)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sakila |
| sample |
| sys |
| world |
+--------------------+
7 rows in set (0.00 sec)
이후 책에서 하라는 대로 하면 다음과 같은 오류가 발생
PS C:\Users\Downloads> mysql -u root -p sample < sample.dump
위치 줄:1 문자:25
+ mysql -u root -p sample < sample.dump
+ ~
'<' 연산자는 나중에 사용하도록 예약되어 있습니다.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : RedirectionNotSupported
원인
powershell에선 '<' 연산자를 입력 pipe로 사용할 수 없음
해결
- Get-Content 사용
: 해당 파일의 내용을 읽는 Get-Content cmdlet을 이용해 파일 로딩 후 mysql 명령어를 실행하는 다음과 같은 방식 사용
Get-Content sample.dump | mysql.exe -uroot -p sample
참고
https://ko.linux-console.net/?p=8805
- cmd 사용
cmd.exe 는 '<'를 사용가능함. 따라서 다음과 같은 방식 사용
cmd /c 'mysql.exe -uroot -p service < sample.dump'
- WSL 내 linux 사용
WSL(Windows Subsystem For Linux) 을 띄우고 bash 그대로 사용(리눅스에선 '<' 사용 가능)
참고
https://stackoverflow.com/questions/2148746/the-operator-is-reserved-for-future-use
+ 나는 cmd 사용 방식으로 성공함
PS C:\Users\Downloads> cmd /c 'mysql.exe -uroot -p sample < sample.dump'
Enter password: ****
PS C:\Users\JAY\Downloads>
'공부 > TIL' 카테고리의 다른 글
[SQL 첫걸음] 2장 06강 검색 조건 지정하기 (0) | 2023.11.13 |
---|---|
[SQL 첫걸음] 2장 05강 테이블 구조 참조하기 (0) | 2023.11.11 |
[SQL 첫걸음] 2장 04강 테이블에서 데이터 검색 (0) | 2023.11.06 |
[SQL 첫걸음] 1장 03강 데이터베이스 서버 (0) | 2023.11.06 |
[SQL 첫걸음] 1장 02강 다양한 데이터베이스 (1) | 2023.11.02 |