mysql 기본 사용법 > 개발자팁

매출이 오르면 내리는 수수료! 지금 수수료센터에서 전자결제(PG)수수료 비교견적 신청해 보세요!

개발자팁

개발과 관련된 유용한 정보를 공유하세요.
질문은 QA에서 해주시기 바랍니다.

mysql 기본 사용법 정보

MySQL mysql 기본 사용법

본문

mysql> show databases;

                                                    - 현제 생성된 데이터 베이스 보기
+----------+
| Database |
+----------+
| mysql      |
+----------+
1 row in set (0.00 sec)

 

mysql> create database test;            - test 라는 데이터 베이스 생성
Query OK, 1 row affected (0.01 sec)

 

mysql> show databases;               
+----------+
| Database |
+----------+
| mysql      |
| test         |
+----------+
2 rows in set (0.00 sec)

 

mysql> use test;                               - test 데이터 베이스를 사용함
Database changed


mysql> create table saram(id char(10), name char(20), age int); 

                                             - test 데이터 베이스에 saram 이라는 테이블 생성
Query OK, 0 rows affected (0.04 sec)

                      

 

mysql> describe saram;                           - 테이블의 목록을 본다
+-------+----------+------+-----+---------+-------+
| Field   | Type       | Null   | Key |  Default  | Extra   |
+-------+----------+------+-----+---------+-------+
| id       | char(10)  | YES  |        | NULL     |          |
| name  | char(20)  | YES  |        | NULL     |          |
| age    | int(11)     | YES  |        | NULL     |          |
+-------+----------+------+-----+---------+-------+
3 rows in set (0.02 sec)

 

mysql> desc saram;                                -  목록 보기의 다른 명령어
+-------+----------+------+-----+---------+-------+
| Field   | Type       | Null   | Key | Default | Extra     |
+-------+----------+------+-----+---------+-------+
| id       | char(10)  | YES  |        | NULL     |          |
| name  | char(20)  | YES  |        | NULL     |          |
| age    | int(11)      | YES  |       | NULL     |          |
+-------+----------+------+-----+---------+-------+
3 rows in set (0.01 sec)

 

mysql> insert into saram(id, name, age) values('aaa','gildong', 32);   
                                               - 생성된 테이블에 정보를 넣는 구문

Query OK, 1 row affected (0.02 sec)

 

mysql> select * from saram;        - 테이블의 내용 보기
+------+---------+------+
| id     | name      | age  |
+------+---------+------+
| aaa   | gildong  |   32   |
+------+---------+------+
1 row in set (0.00 sec)

 

mysql> select name, age from saram;         - 테이블의 내용중 원하는 부분만 보기
+---------+------+
| name     | age   |
+---------+------+
| gildong  |   32   |
+---------+------+
1 row in set (0.01 sec)

 

mysql> insert into saram values('bbb','sunshin',400);           - 데이터를 넣는 다른 유형
Query OK, 1 row affected (0.01 sec)

 

mysql> insert into saram values('ccc','ginea',20);       
Query OK, 1 row affected (0.01 sec)

 

mysql> select * from saram;             
+------+---------+------+
| id      | name     | age  |
+------+---------+------+
| aaa   | gildong  |   32   |
| bbb   | sunshin |  400  |
| ccc   | ginea     |   20  |
+------+---------+------+
3 rows in set (0.00 sec)

 

mysql> update saram set name='jinea' where id='ccc';        
                           - 테이블 내 데이터 수정

                            * 주의할점 where id 를 넣지않으면 테이블 내에 모든 내용이 바뀐다

Query OK, 1 row affected (0.02 sec)
Rows matched: 1  Changed: 1  Warnings: 0

 

mysql> select * from saram;               
+------+---------+------+
| id      | name     | age  |
+------+---------+------+
| aaa   | gildong  |   32   |
| bbb   | sunshin |  400  |
| ccc   | jinea      |   20  |
+------+---------+------+
3 rows in set (0.01 sec)

 

mysql> alter table saram change age nai tinyint;         
                 - 테이블의 목록 이름 및 변수타입을 바꿔주는 명령어

Query OK, 3 rows affected, 1 warning (0.10 sec)
Records: 3  Duplicates: 0  Warnings: 1

 

mysql> select * from saram;      
+------+---------+------+
| id     | name     | nai    |            - 목록 이름이 바뀌었다
+------+---------+------+
| aaa  | gildong   |   32   |
| bbb  | sunshin  |  127  |            - tinyint 의 값이 -128~127 이기 때문에
| ccc  | jinea       |   20  |               127 초과 값인 400이 127로 바뀐다
+------+---------+------+
3 rows in set (0.00 sec)

 

mysql> delete from saram where id='ccc';           
                             - 데이터 삭제 여기서도 where id 를 같이 쓰지 않으면 모두 삭제된다

Query OK, 1 row affected (0.00 sec)

 

mysql> select * from saram;           
+------+---------+------+
| id   | name    | nai  |
+------+---------+------+
| aaa  | gildong |   32 |
| bbb  | sunshin |  127 |
+------+---------+------+
2 rows in set (0.00 sec)

 

mysql> drop table saram;                   - 테이블 삭제 명령
Query OK, 0 rows affected (0.01 sec)

 

mysql> show tables;      
Empty set (0.02 sec)

 

mysql> show databases;              
+----------+
| Database |
+----------+
| mysql      |
| test         |
+----------+
2 rows in set (0.02 sec)

 

mysql> drop database test;          - 데이터베이스 삭제 명령
Query OK, 0 rows affected (0.01 sec)

 

mysql> show databases;            
+----------+  
| Database |
+----------+
| mysql      |
+----------+
1 row in set (0.00 sec)

 

mysql>

 

mysql> set password = password('변경할 패스워드');      -  패스워드변경

추천
0

댓글 0개

전체 470
개발자팁 내용 검색 MySQL에서

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1404호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT