Mysql이 설치 되어있다고 가정 한다.



update user set password=password('123456') where user='root'



위의 Query를 작성 한다.

'Database' 카테고리의 다른 글

Mysql Windows Can''t connect to MySQL server on 'localhost' (10061)  (0) 2012.12.07
Mysql Timestamp Column 생성 하기  (0) 2012.12.06
Oracle 덤프 뜨기  (0) 2012.11.26
count() 에 대해서  (0) 2012.11.16
having 사용하기  (0) 2012.11.15


1. EXP 추출 하기



exp testid/testpw file=./test.dmp



2. IMP 입력 하기


IGNORE=Y 옵션을 추가 할 경우, 데이터를 덮어 씌운다.

TABLES=TABLE_NAME 추가 할 경우, 해당 테이블만 IMPORT 한다. (단 해당 테이블은 삭제 해야 한다.)



imp testid/testpw IGNORE=Y TABLES=table_name FROMUSER=fromtestid TOUSER=totestid file=./test.dmp




'Database' 카테고리의 다른 글

Mysql Timestamp Column 생성 하기  (0) 2012.12.06
Mysql root 비밀번호 변경하기  (0) 2012.12.03
count() 에 대해서  (0) 2012.11.16
having 사용하기  (0) 2012.11.15
Mysql 사용자 생성 하기  (0) 2012.11.13

 

 Sql을 작성하면, 일반적인 Select 가 아닌 합이나, 통계 등 다양한 조건을 수용하기 위해서는 count() 라는 함수를 사용하게 된다. 아래 목록을 보자.

 

 

 

    • 값을 셀 수 있다.
    • 행을 셀 수 있다.
    • NULL이 아닌 것을 의미 한다.

 

 

 

 크게 3가지로 구분 할 수 있다. count()는 사용 할 경우, 단순히 결과에 있는 행 수를 세게 된다. 괄호 안에 있는 내용은 표현이 절대 NULL을 가질 수 없다는 조건을 염두해 두고 동작 한다고 한다.

 

※ 참고 서적: [Mysql 성능 최적화 - 베론 슈와츠, 피터 제이트세브, 바딤 카첸코, 제레미 자워드니, 아르엔 렌츠, 데렉 볼링 지음][04장 쿼리 성능 최적화]

'Database' 카테고리의 다른 글

Mysql Timestamp Column 생성 하기  (0) 2012.12.06
Mysql root 비밀번호 변경하기  (0) 2012.12.03
Oracle 덤프 뜨기  (0) 2012.11.26
having 사용하기  (0) 2012.11.15
Mysql 사용자 생성 하기  (0) 2012.11.13

 

 sql을 작성 하는데 데이터의 특정 조건의 합, 특정 값 이상 등 group by를 해야할 경우가 생길 수 있다. 이와 같은 경우 inline view를 이용하여 처리를 할 수도 있지만, having을 이용하면 처리 하기가 유용하다. 직접 사용해보도록 하자.

 

 Mysql은 설치되어 있다고 가정 한다. 아래 sql을 실행 하자.

 

 

create table tt_date (
    tt_time timestamp,
    title varchar(10)
);

 

insert into tt_date values ('2012-01-01','title1');
insert into tt_date values ('2012-01-02','title2');
insert into tt_date values ('2012-01-03','title3');
insert into tt_date values ('2012-01-04','title4');
insert into tt_date values ('2012-01-05','title5');
insert into tt_date values ('2012-01-06','title6');
insert into tt_date values ('2012-02-07','title7');
insert into tt_date values ('2012-02-08','title8');
insert into tt_date values ('2012-02-09','title9');
insert into tt_date values ('2012-02-10','title10');
insert into tt_date values ('2012-02-11','title11');
insert into tt_date values ('2012-03-12','title12');
insert into tt_date values ('2012-03-13','title13');
insert into tt_date values ('2012-03-14','title14');
insert into tt_date values ('2012-03-15','title15');

 

 

 테이블을 생성 했을 것 이다. 아래의 조건을 보도록 하자.

 

 

Step 1. 1월 데이터만 출력 하기.

 

 

select tt_time from tt_date group by tt_time having month(tt_time) = 1

 

 

 

Step2. 1월 3일 ~ 1월 5일 데이터만 출력 하기.

 

 

select tt_time from tt_date

group by tt_time having month(tt_time) = 1 && day(tt_time) > 2 && day(tt_time) < 6

 

 

 

사용한 날짜 함수.

 

  • month(date): 날짜에 대한 월을 반환 한다.
  • day(date): 날짜에 대한 일을 반환 한다.

 

group by 후에 조건을 걸어 조회를 할 수 있다. 날짜 함수와 같이 사용하여 알아보았다.

 

'Database' 카테고리의 다른 글

Mysql Timestamp Column 생성 하기  (0) 2012.12.06
Mysql root 비밀번호 변경하기  (0) 2012.12.03
Oracle 덤프 뜨기  (0) 2012.11.26
count() 에 대해서  (0) 2012.11.16
Mysql 사용자 생성 하기  (0) 2012.11.13

 Mysql이 설치가 되어 있다고 가정 한다.

Step 1. 데이터베이스 생성

 생성할 사용자가 사용하는 데이터베이스를 생성 한다. 생성시 명시를 해줘야 하기 때문에 먼저 작업 한다.

 create database if not exists [데이터베이스 명]

 create database if not exists whitelife;


 Step 2. 사용자 생성

 사용자를 생성 한다. 접속을 허용할 IP를 whitelife@IP 작성 하거나 '%' 모든 접속이 허용 된다.

 grant usage on [데이터베이스 명].* to [사용자 명]@[호스트] indentified by [비밀번호];

grant usage on whitelife.* to whitelife@localhost identified by 'whitelife';
grant usage on whitelife.* to whitelife@'127.0.0.1' identified by 'whitelife';
grant usage on whitelife.* to whitelife@'%' identified by 'whitelife';


 Step 3. 권한 부여

 권한을 부여 한다. 최소한 권한만 정의 하였다. 사용자 생성시 3가지 종류로 작성 하였다면 권한도 3가지 다 부여해야 한다.

grant select, insert, update, delete, create, drop, index, alter on whitelife.* to whitelife@localhost;
grant select, insert, update, delete, create, drop, index, alter on whitelife.* to whitelife@'127.0.0.1';
grant select, insert, update, delete, create, drop, index, alter on whitelife.* to whitelife@'%';


 Step 4. 적용 하기

 아래 명령어를 실행 한다.

flush privileges;


  Step 5. 확인 하기

 생성한 사용자로 로그인하여 확인해보자. 정상적으로 접속 되는 것을 확인 할 수 있다.

C:\Program Files\MySQL\MySQL Server 5.5\bin>mysql -u whitelife -p whitelife
Enter password: *********
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 29
Server version: 5.5.28 MySQL Community Server (GPL)

Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.

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>


'Database' 카테고리의 다른 글

Mysql Timestamp Column 생성 하기  (0) 2012.12.06
Mysql root 비밀번호 변경하기  (0) 2012.12.03
Oracle 덤프 뜨기  (0) 2012.11.26
count() 에 대해서  (0) 2012.11.16
having 사용하기  (0) 2012.11.15

+ Recent posts