[18]MySQL DB

MySQL DB

다운 및 설치

  1. http://www.mysql.com](http://www.mysql.com/) -> Downloads -> MySQL Community Edition (GPL) Community (GPL) Downloads -> MySQL Community Server -> DOWNLOAD -> 5.6.20 내 컴퓨터에서 OS의 비트를 확인하여 다운로드 OS 32 bit/JDK 32 bit:
    Windows (x86, 32-bit), ZIP Archive (mysql-5.6.20-win32.zip)
  2. ​ OS 64 bit/JDK 64 bit:
    ​ Windows (x86, 64-bit), ZIP Archive (mysql-5.6.40-winx64.zip) -> No thanks, just start my download.
  3. “mysql-5.6.40-winx64.zip” 현재 폴더에 압축을 해제합니다.
  4. “mysql-5.6.40-winx64” 폴더 이름을 “mysql-5.6”로 변경하여 ‘d:/java0123’ 폴더로 이동
  5. 최종 설치된 경로: ‘d:/java0123/mysql-5.6’
  6. MySQL이 이미 설치되어 있다면 충돌 제거를 위해 ‘프로그램 및 기능’에서 삭제하거나 [제어판 -> 관리 도구 -> 서비스]에서 Mysql로 시작하는 서비스를 전부 ‘수동’, ‘중지’ 옵션을 지정하세요.

MySQL 서버 작동 시작

  • D:\java0123\mysql-5.6\bin\mysqld.exe 더블클릭 mysqld.exe가 [작업관리자->프로세스]에 실행중인지 확인

※ [MSVCR100.dll] 파일 오류

vcredist_x64.exe 다운후 설치 (관리자 권한 실행)

위의 사항으로 했는데도 계속 에러 발생이 되면 제어판에서 기존 Microsoft Visual C++ 파일 전부 제거한 후 컴퓨터 재부팅하고 vcredist_x64.exe 다시 설치

MySQL 서버 작동 시작

  • [작업관리자->프로세스]에서 mysqld.exe 프로세스 끝내기

MySQL root 계정 비밀번호 계정

  • MySQL 서버 실행 (mysqld.exe)
  • root계정으로 접속 : 최고 관리자 계정이며, 처음 MySQL설치 시 패스워드가 지정되어 있지 않다 cmd창에서 d: cd D:\java0123\mysql-5.6\bin 폴더 이동 D:\java0123\mysql-5.6\bin>mysql -u root //-u: 계정지정
  • mysql>show databases;
  • mysql>use mysql; //mysql 데이터베이스 사용
  • mysql>show tables; //mysql 데이터베이스에 있는 테이블 보기
  • mysql>select host,user,password from user; //user테이블의 레코드 보기
  • mysql>update user SET password=PASSWORD(‘1234’) where user=’root’; //root계정의 비밀번호 ‘1234’를 암호화해서 수정한다.
  • mysql>flush privileges; //권한 및 계정 정보를 서버에 재적용한다.
  • mysql>select host,user,password from user; //user테이블의 수정된 레코드 보기
  • mysql>exit //MySQL 빠져 나가기
비밀번호 지정후 다시 root계정으로 접속
  • d:\java0123\mysql-5.6\bin>mysql -u root -p
    • //-u: 로그인 계정 지정
    • //-p: 패스워드를 입력받는 계정임을 명시, 패스워드가 있으면 반드시 명시

※ MySQL 5.7 이상은 패스워드를 영소문자+영대문자+숫자+특수기호를 포함된 최소 8자리 이상 >mysql -u root >show databases; >use mysql;

​ >show tables; ​ >select * from user; ​ >select user,authentication_string from user;

​ >update user set authentication_string=PASSWORD(‘Soldesk1234~’) where user=’root’; ​ >flush privileges; ​ >exit


MySQL DB 생성 및 삭제

  • 데이터베이스 목록 보기
    • show databases;
  • 데이터베이스 생성
  • create database DB명;
  • create database mydb;
  • 데이터베이스 삭제
    • drop database DB명;
    • drop database mydb;
  • 데이터베이스 사용
    • use DB명
    • use mydb

ENGINE 설정 및 문자셋 지정

1)테이블 ENGINE 설정

  • MYSQL 에서는 Table 마다 다른 ENGINE 을 사용 할 수 있다.
  • MyISAM
    • 읽기 위주 요청에 높은 성능 테이블 단위로 locking (트랜잭션 안됨)
  • InnoDB
    • 트랜잭션 지원빈번한 수정, 삭제시 처리 능력 뛰어남 디스크, 전원 등의 장애 시 복구 성능이 좋음.
    • 동시 처리가 많은 환경에 적합함 ROW 단위 locking
  • MEMORY
    • Hash 인덱스 사용 하여 빠름 (테이블 스키마는 남음)
    • 전원 off 시 데이터 삭제 됨

예) 테이블 생성 시

1
2
3
CREATE TABLE memory_test(test_idx int, test_name char(5)) ENGINE=MEMORY;
CREATE TABLE innodb_test(test_idx int, test_name char(5)) ENGINE=InnoDB;
CREATE TABLE myisam_test(test_idx int, test_name char(5)) ENGINE=MyISAM;

2) 문자셋 지정

  • 완성형 : euckr
  • 조합형 : utf8
1
2
3
4
5
6
7
8
9
10
create table sungjuk (
  sno   int not null auto_increment primary key,
  uname varchar(20) not null,
  kor   tinyint     not null,
  eng   tinyint     not null,
  mat   tinyint     not null,
  tot   int         null default 0,
  aver  int         null default 0,
  regdt datetime    not null
)ENGINE=MyISAM DEFAULT CHARSET="euckr";