MySQL 설치, 연결, 설정이 모두 끝났다.
이제 데이터베이스(이하 DB)를 만들어 이클립스와 연동을 해보려고 한다.
*처음 보신 분들은 MySQL 설치 과정부터 따라오시면 됩니다 :)
1) 먼저 서버를 실행하고 root 계정으로 접속한다.
현재 DB를 조회해보자.
☞ mysql>show databases;

2) 우리가 사용할 새 DB를 생성하자.(명령어를 입력할 때 대,소문자 구분을 하지 않는다)
☞ mysql>CREATE DATABASE shxdb;
*shxdb : 생성하고자 하는 DB 이름 입력
다시 DB를 조회해보면 정상적으로 생성된 것을 확인할 수 있다.
☞ mysql>SHOW DATABASES;

3) 이제 잠시 서버는 내려두고, bat파일을 만들어서 MySQL의 실행을 컨트롤하자.
(예전에 국비교육을 받을 당시 배웠던 방법인데 꽤 편리하다)
아래 코드를 메모장 또는 EditPlus를 실행해서 입력하고 저장을 할 때 mysql.bat 형식으로 하면 된다.
설정된 계정(root)으로 DB에 접근하는 코드이다.
-p 뒤 숫자 1234 : 계정의 비밀번호
shxdb : 접근하려는 DB
| D: CD/ CD mysql57/bin start mysqld.exe REM pause REM start mysql.exe -u root -p1234 shxdb | cs |

4) 다시 https://www.mysql.com 사이트에 접속한다. DOWNLOADS 클릭

5) 스크롤을 내려 MySQL Community Edition(GPL) Community(GPL) Downloads 클릭

6) 중간쯤 MySQL Connectors가 있다. DOWNLOAD 클릭

7) Connector/J 클릭

8) 최신 버전이 있지만 예전 버전을 받았다.(예전에 써본 버전이기도 하고 안정적인게 좋아서..)

9) Download 클릭

10) 다운 받은 zip파일은 여기에 풀기로 압축을 푼다.

11.1) jar 파일을 복사하여 자신이 원하는 경로로 옮겨준다.

11.2) 나는 mysql의 폴더로 옮겨줬다. 파일 이름이 길기 때문에 바꿔주는 것도 좋다.(mysql-connector.jar)
다음 단계부터 이클립스에서 MySQL을 연동할 것이기 때문에 mysql.bat 파일을 실행해준다.

12) 작업 관리자를 열어 MySQL이 정상적으로 실행되는지 확인한다.

13) 이클립스를 열고 Window -> Show View -> Other 클릭

14) Data Managerment -> Data Source Explorer 클릭

15) 아래 악수하는 모양(?) New Connection Profile 클릭

참고로 이클립스 최신 버전인 PHOTON을 사용하고 있었는데 PHOTON에서는 아래와 같은 화면만 나오고 진전이 안돼서 방법을 찾다가 버전을 하나 낮춰봤다... 그래서 현재 이클립스 버전은 Oxygen인데 정상적으로 나오더라. 참고하시길!
<Eclipse PHOTON>

<Eclipse Oxygen>
16) MySQL 선택 후 Name은 root로 했다. (원하는 이름을 적어도 좋다)
Next 클릭

17) 빨간 표시 부분(New Driver Definition) 클릭

18) Database 중 MySQL JDBC Driver 5.1 Version 선택 후 JAR List 클릭

19) 기존에 있는 jar파일을 Remove JAR/Zip하고 Add JAR/Zip을 클릭

20) 11.2에서 자신이 저장한 mysql-connector.jar 파일을 찾아 열고 OK를 클릭

21.1) 기존 database로 입력되어있는 부분을 자신이 만든 DB( 2)참조 )를 입력하고 password는
자신이 설정한 비밀번호( MySQL 설치-11)참조 )를 입력해주면 된다. 그리고 Test Connection 클릭

21.2) Ping succeded! 가 뜨면 성공. Next 클릭
혹시 Ping failed!가 뜬다면 비밀번호를 맞게 입력했는지 또는 MySQL이 실행중인지 확인해보자.

22) 설정 내역을 확인 후 Finish 클릭

23) DB가 정상적으로 연결된 것을 확인할 수 있다.
이클립스 재접속 시 따로 Connection을 해주면 된다.(MySQL을 실행 후)

<이클립스 재접속>

다음 장에서는 DB툴 없이 이클립스에서 MySQL을 다루는 방법을 설명하도록 하겠습니다.