728x90
MySQL?
MySQL은 데이터 소프트웨어입니다. 일반적으로 데이터를 추가하거나 검색, 추출하는 기능을 모두 포함해서 데이터베이스라고 부릅니다.
MySQL은 세계에서 가장 많이 쓰이는 오픈 소스의 관계형 데이터베이스 관리시스템(RDBMS)입니다. MySQL은 PHP 스크립트 언어와 상호 연동이 잘 되면서 오픈소스를 개발된 무료 프로그램입니다. 그래서 홈페이지나 쇼핑몰(워드프레스, cafe24, 제로보드, 그누보드)등 일반적으로 웹 개발에 널리 사용하고 있습니다.
MySQL 설치
MAMP란 웹사이트를 개발할 때 쓰이는 기술 스택인 macOS, Apache, MySQL, pHP 의 약어이자 솔루션 스텍이다
https://www.mamp.info/en/downloads/
https://www.mamp.info/en/downloads/
MySQL 실행
윈도우 : cs MAMP/bin/mysql/bin
로그인 : mysql -uroot -proot
로그인 : mysql -uroot -proot
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.24 MySQL Community Server (GPL)
Copyright (c) 2000, 2018, 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.
맥 : cd Application/mamp/Library/bin
로그인 : ./mysql -uroot -proot
로그인 : ./mysql -uroot -proot
gimsangjun@gimsangjun-ui-MacBookAir bin % ./mysql -uroot -proot
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.34 MySQL Community Server (GPL)
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
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.
데이터베이스
데이터베이스 만들기
create database [데이터 베이스 이름];
mysql> create database sample01;
Query OK, 1 row affected (0.01 sec)
데이터베이스 보기
show databases;
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sample01 |
| sys |
+--------------------+
5 rows in set (0.00 sec)
데이터베이스 사용
use 데이터베이스 이름;
mysql> use sample01;
Database changed
데이터베이스 삭제
drop database [데이터 베이스 이름];
mysql> drop database sample02;
Query OK, 0 rows affected (0.01 sec)
테이블
테이블 만들기
create table member (
myMemberID int(10) unsigned auto_increment,
youEmail varchar(40) NOT NULL,
youName varchar(20) NOT NULL,
youPass varchar(20) NOT NULL,
youBirth int(20) NOT NULL,
regTime int(20) NOT NULL,
PRIMARY KEY (myMemberID)
) charset=utf8;
mysql> create table member (
-> myMemberID int(10) unsigned auto_increment,
-> youEmail varchar(40) NOT NULL,
-> youName varchar(20) NOT NULL,
-> youPass varchar(20) NOT NULL,
-> youBirth int(20) NOT NULL,
-> regTime int(20) NOT NULL,
-> PRIMARY KEY (myMemberID)
-> ) charset=utf8;
Query OK, 0 rows affected (0.03 sec)
테이블 전체보기
show tables;
mysql> show tables;
+--------------------+
| Tables_in_sample01 |
+--------------------+
| member |
+--------------------+
1 row in set (0.00 sec)
테이블 보기
desc 테이블 이름;
mysql> desc member;
+------------+------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------+------------------+------+-----+---------+----------------+
| myMemberID | int(10) unsigned | NO | PRI | NULL | auto_increment |
| youEmail | varchar(40) | NO | | NULL | |
| youName | varchar(20) | NO | | NULL | |
| youPass | varchar(20) | NO | | NULL | |
| youBirth | int(20) | NO | | NULL | |
| regTime | int(20) | NO | | NULL | |
+------------+------------------+------+-----+---------+----------------+
6 rows in set (0.02 sec)
테이블 삭제
drop table 테이블 이름;
mysql> drop table member;
Query OK, 0 rows affected (0.01 sec)
테이블 데이터
테이블 데이터 추가
INSERT INTO 테이블 이름(필드명) VALUE(데이터)
NSERT INTO member(youEmail, youName, youPass, youBirth, regTime) VALUES('ooooooo@naver.com', '1234', '19940404', '1234567');
INSERT INTO member(youEmail, youName, youPass, youBirth, regTime) VALUES('ooooo_oooooo@naver.com','1234','19990303','1234567');
INSERT INTO member(youEmail, youName, youPass, youBirth, regTime) VALUES('ooooo_oooooo@naver.com', '1234', '19970415', '1234567');
INSERT INTO member(youEmail, youName, youPass, youBirth, regTime) VALUES('ooooo_oooooo@naver.com', '1234', '19970530', '1234567');
INSERT INTO member(youEmail, youName, youPass, youBirth, regTime) VALUES('ooooo_oooooo@naver.com', '1234', '19941009', '1234567');
INSERT INTO member(youEmail, youName, youPass, youBirth, regTime) VALUES('ooooo_oooooo@naver.com', '1234', '19990303', '1234567');
INSERT INTO member(youEmail, youName, youPass, youBirth, regTime) VALUES('ooooo_oooooo@gmail.com', '1234', '20011009','1234567');
INSERT INTO member(youEmail, youName, youPass, youBirth, regTime) VALUES('ooooo_oooooo@naver.com','1234','19970205','1234567');
INSERT INTO member(youEmail, youName, youPass, youBirth, regTime) VALUES('ooooo_oooooo@naver.com','1234','19990303','1234567');
INSERT INTO member(youEmail, youName, youPass, youBirth, regTime) VALUES('ooooo_oooooo@naver.com','1234','19990303','1234567');
INSERT INTO member(youEmail, youName, youPass, youBirth, regTime) VALUES('ooooo_oooooo@gmail.com', '1234', '19990303', '1234567');
INSERT INTO member(youEmail, youName, youPass, youBirth, regTime) VALUE('ooooo_oooooo@gmail.com', '1234', '19990303', '1234567');
INSERT INTO member(youEmail, youName, youPass, youBirth, regTime) VALUES('ooooo_oooooo@gmail.com','1234','19970731','1234567');
INSERT INTO member(youEmail, youName, youPass, youBirth, regTime) VALUES('ooooo_oooooo@naver.com','1234','19960530','1234567')
INSERT INTO member(youEmail, youName, youPass, youBirth, regTime) VALUES('ooooo_oooooo@gmail.com','1234','19971007','1234567');
INSERT INTO member(youEmail, youName, youPass, youBirth, regTime) VALUES('ooooo_oooooo@gmail.com','1234','19960331','1234567');
INSERT INTO member(youEmail, youName, youPass, youBirth, regTime) VALUES('ooooo_oooooo@gmail.com','1234','19990303','1234567');
INSERT INTO member(youEmail, youName, youPass, youBirth, regTime) VALUES('ooooo_oooooo@gmail.com', '1234', '19981010', '1234567');
INSERT INTO member(youEmail, youName, youPass, youBirth, regTime) VALUE('ooooo_oooooo@gmail.com', '1234', '19700101', '1234567');
INSERT INTO member(youEmail, youName, youPass, youBirth, regTime) VALUES('ooooo_oooooo@gmail.com', '1234', '19990303', '1234567');
INSERT INTO member(youEmail, youName, youPass, youBirth, regTime) VALUES('ooooo_oooooo@naver.com', '3950', '20010415', '1234567');
테이블 불러오기
SELECT 필드명 FROM 테이븗명 WHERE 조건
전체 데이터 불러오기
예)SELECT * FROM member;
mysql> SELECT * FROM member;
+------------+------------------------+------------+---------+----------+---------+
| myMemberID | youEmail | youName | youPass | youBirth | regTime |
+------------+------------------------+------------+---------+----------+---------+
| 1 | ooooo_oooooo@naver.com | 홍길동 | 1234 | 19940404 | 4 |
| 2 | ooooo_oooooo@naver.com | 홍길동 | 1234 | 19940404 | 1234567 |
| 3 | ooooo_oooooo@naver.com | 홍길동 | 1234 | 19990303 | 1234567 |
| 4 | ooooo_oooooo@naver.com | 홍길동 | 1234 | 19970415 | 1234567 |
| 5 | ooooo_oooooo@naver.com | 홍길동 | 1234 | 19970530 | 1234567 |
| 6 | ooooo_oooooo@naver.com | 홍길동 | 1234 | 19941009 | 1234567 |
| 7 | ooooo_oooooo@naver.com | 홍길동 | 1234 | 19990303 | 1234567 |
| 8 | ooooo_oooooo@naver.com | 홍길동 | 1234 | 20011009 | 1234567 |
| 9 | ooooo_oooooo@naver.com | 홍길동 | 1234 | 19970205 | 1234567 |
| 10 | ooooo_oooooo@naver.com | 홍길동 | 1234 | 19990303 | 1234567 |
| 11 | ooooo_oooooo@naver.com | 홍길동 | 1234 | 19990303 | 1234567 |
| 12 | ooooo_oooooo@naver.com | 홍길동 | 1234 | 19990303 | 1234567 |
| 13 | ooooo_oooooo@naver.com | 홍길동 | 1234 | 19990303 | 1234567 |
| 14 | ooooo_oooooo@naver.com | 홍길동 | 1234 | 19970731 | 1234567 |
| 15 | ooooo_oooooo@naver.com | 홍길동 | 1234 | 19960331 | 1234567 |
| 16 | ooooo_oooooo@naver.com | 홍길동 | 1234 | 19990303 | 1234567 |
| 17 | ooooo_oooooo@naver.com | 홍길동 | 1234 | 19981010 | 1234567 |
| 18 | ooooo_oooooo@naver.com | 홍길동 | 1234 | 19700101 | 1234567 |
| 19 | ooooo_oooooo@naver.com | 홍길동 | 1234 | 19990303 | 1234567 |
| 20 | ooooo_oooooo@naver.com | 홍길동 | 3950 | 20010415 | 1234567 |
+------------+------------------------+------------+---------+----------+---------+
20 rows in set (0.01 sec)
myMemberID가 6번인 경우
예) SELECT * FROM member WHERE myMemberID = 6
mysql> SELECT * FROM member WHERE myMemberID = 6;
+------------+-----------------------+-----------+---------+----------+---------+
| myMemberID | youEmail | youName | youPass | youBirth | regTime |
+------------+-----------------------+-----------+---------+----------+---------+
| 6 | ooooo_ooooo@naver.com | 김수용 | 1234 | 19941009 | 1234567 |
+------------+-----------------------+-----------+---------+----------+---------+
1 row in set (0.01 sec)
email 중에 naver 텍스트를 포함하고 있는 경우
예) SELECT * FROM member WHERE youEmail LIKE '%naver%';
mysql> SELECT * FROM member WHERE youEmail LIKE '%naver%';
+------------+------------------------+------------+---------+----------+---------+
| myMemberID | youEmail | youName | youPass | youBirth | regTime |
+------------+------------------------+------------+---------+----------+---------+
| 1 | oooo_ooooooo@gmail.com | 홍길동 | 1234 | 19940404 | 4 |
| 2 | oooo_ooooooo@gmail.com | 홍길동 | 1234 | 19940404 | 1234567 |
| 3 | oooo_ooooooo@gmail.com | 홍길동 | 1234 | 19990303 | 1234567 |
| 4 | oooo_ooooooo@gmail.com | 홍길동 | 1234 | 19970415 | 1234567 |
| 5 | oooo_ooooooo@gmail.com | 홍길동 | 1234 | 19970530 | 1234567 |
| 6 | oooo_ooooooo@gmail.com | 홍길동 | 1234 | 19941009 | 1234567 |
| 7 | oooo_ooooooo@gmail.com | 홍길동 | 1234 | 19990303 | 1234567 |
| 9 | oooo_ooooooo@gmail.com | 홍길동 | 1234 | 19970205 | 1234567 |
| 10 | oooo_ooooooo@gmail.com | 홍길동 | 1234 | 19990303 | 1234567 |
| 11 | oooo_ooooooo@gmail.com | 홍길동 | 1234 | 19990303 | 1234567 |
| 20 | oooo_ooooooo@gmail.com | 홍길동 | 3950 | 20010415 | 1234567 |
+------------+------------------------+------------+---------+----------+---------+
11 rows in set (0.01 sec)
테이블 데이터
INSERT INTO 테이블 이름(필드명) VALUE(데이터)
INSERT INTO member(youEmail, youName, youPass, youBirth, regTime) VALUES('to_before@naver.com', '김상준', '1234', '19940404', '04')
테이블 데이터
INSERT INTO 테이블 이름(필드명) VALUE(데이터)
INSERT INTO member(youEmail, youName, youPass, youBirth, regTime) VALUES('to_before@naver.com', '김상준', '1234', '19940404', '04')
728x90
반응형
댓글