Mysql 명령어 정리 Database

 

 데이터베이스 관련 명령어

 - mysql> show databases;          //DB 목록보기

 - mysql> use db명;                //사용할 DB 선택  

 - mysql> show tables;             //테이블 목록 보기


 
 테이블 정의 명령어(create, alter, drop)

// 테이블 구조(필드) 변경하기

 

  (1) 필드 추가

     mysql> alter table customer add age int;

     mysql> desc customer;

  (2) 필드 삭제

     mysql> alter table customer drop age;

     mysql> desc customer;

 (3) 필드 수정

     mysql> alter table customer change phone tel int;

     mysql> desc customer;

  (4) 필드 타입 수정

     mysql> alter table customer modify tel char(12);

     mysql> desc customer;

 (5) 테이블 이름 변경

     mysql> alter table customer rename new_customer;

     mysql> show tables;

 //테이블 삭제

  mysql> drop table new_customer;

  mysql> show tables;


 

데이터 조작 명령어(select, insert, update, delete)

 // 데이터 조회

 mysql> select * from customer;

 // 데이터 삽입

mysql> insert into customer values('1','Kil-Dong','Hong','123-4567');
insert into
customer values('2','Gwan-Soon','You','234-5678');
insert into
customer values('3','Chan-Ho','Park','345-6789');
insert into
customer values('4','Tae-Hwan','Park','456-7890');
insert into
customer values('5','Mi-Ja','Lee','567-8901');
insert into
customer values('6','Bum','Baek','678-9012');
insert into
customer values('7','Man-Soo','Lee','789-0123');

mysql> select * from customers;

 

mysql> select f_name, phone
         from
customer
         where
l_name='Lee';


// 데이터 수정

mysql> update customer

        set phone = '111-1111'

        where id = '3';

 

mysql> select *
         from
customer;

// 데이터 삭제

mysql> delete from customer

        where f_name  = 'bum';

 

mysql> select *
         from
customer;


// 데이터 조회

mysql> select *

        from customer

        order by f_name;

 

mysql> select *
        from
customer

        where f_name like 'M%';


제일 기본적인 것만 정리했음


트랙백

이 글과 관련된 글 쓰기 (트랙백 보내기)
TrackbackURL : http://blockboys2.egloos.com/tb/1364698 [도움말]

덧글

덧글 입력 영역