1 Mysql 설치
-------------------------------------------------------------------
# yum -y install mysql-server  mysql 설치
# /etc/rc.d/init.d/mysqld start  mysql 데몬시작
# mysqladmin -u root password '1234' mysql 아이디/패스워드설정
# mysql -u root -p   mysql접속
mysql> show databases;   DB확인
mysql> create database shop;
mysql> use shop;
-------------------------------------------------------------------
mysql> create table customer(  customer 테이블 생성
> id varchar(10) not null primary key,
> name varchar(20),
> age int,
> address varchar(20)
> );
--------------------------------------------------------------------
mysql> create table purchase(  purchase 테이블 생성
> no int not null primary key auto_increment,
> custom_id varchar(10),
> date char(8),
> product varchar(15)
> );
-------------------------------------------------------------------
테이블의 구조
desc customer;    
desc purchase;
--------------------------------------------------------------------
insert into customer values('hong', '홍길동', 20,'서울시종로구');
insert into customer values('hong5', null, 30, '서울시종로구');
insert into customer values('hong4', '홍길동3', 40, '서울시종로구');

select * from customer;
--------------------------------------------------------------------
insert into purchase(custom_id, date, product) values
('k111','20100225', 'itbank');

insert into purchase(custom_id, date, product) values
('k222','20100225', 'ibbank');

insert into purchase(custom_id, date, product) values
('k333','20100225', 'soldesk');

select * from purchase;
-------------------------------------------------------------------------------
delete from customer where id='hong';  id가 hong인 것 지움
select * from customer;
--------------------------------------------------------------------------------
update customer set name='홍길산', address='서울시 동대문구' where id='hong';
--------------------------------------------------------------------------------
select * from customer order by age desc;  내림차순
--------------------------------------------------------------------------------
이름이 '홍길산' 인 레코드    특정문자열만 찾음
select * from customer where name='홍길산';

이름이 '홍' 으로 시작하는 레코드
select * from customer where name like '홍%';

이름이 '길' 이 들어 있는 레코드
select * from customer where name like '%길%';

이름이 '산'으로 끝나는 레코드 출력..
select * from customer where name like '%산';
--------------------------------------------------------------------------------
나이가 30살 이상인 레코드
select * from customer where age >=30;

나이가 20살에서 30살 사이 레코드
select * from customer where age >=20 and age <=30;
select * from customer where age between 20 and 30;

select * from customer where name is null;  
select * from customer where name is not null;

이름이 '홍'으로 시작하고 나이가 40살인 레코드
select * from customer
where
name like '홍%' and age=30

이름이 '홍' 으로 시작하면서 나이가 많은순으로 이름 나이 출력...
select name, age from customer where name like '홍%'
order by age desc; 

 

검색할 '단어'를 입력하시고, 엔터를 눌러 주세요.