MySQL은 데이터베이스 소프트웨어입니다. 일반적으로 데이터를 추가하거나 검색, 추출하는 기능을 모두 포함해서 데이터베이스라고 부릅니다.
MySQL은 세계에서 가장 많이 쓰이는 오픈 소스의 관계형 데이터베이스 관리 시스템(RDBMS)입니다. MySQL은 PHP 스크립트 언어화 상호 연동이 잘 되면서 오프소스로 개발된 무료 프로그램입니다. 그래서 홈페이지나 쇼핑몰(워드프레스, cafe24, 제로보드, 그누보드)등 일반적으로 웹 개발에 널리 사영하고 있습니다.
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.
mysql>
mysql> create database text01
-> ;
Query OK, 1 row affected (0.00 sec)
mysql> show databases
-> ;
mysql> use sample03
Database changed
mysql> drop database sample02
-> ;
Query OK, 0 rows affected (0.00 sec)
CREATE TABLE myMember (
memberID 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,
youAge int(20) NOT NULL,
youPhone int(20) NOT NULL,
regTime int(11) NOT NULL,
PRIMARY KEY (memberID)
) charset=utf8;
mysql> show tables
-> ;
+--------------------+
| Tables_in_sample03 |
+--------------------+
| mymember |
+--------------------+
1 row in set (0.00 sec)
mysql> desc myMember
-> ;
+------------+------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------+------------------+------+-----+---------+----------------+
| myMemberID | int(10) unsigned | NO | PRI | NULL | auto_increment |
| youEmail | varchar(40) | NO | | NULL | |
| youName | varchar(12) | NO | | NULL | |
| youPass | varchar(20) | NO | | NULL | |
| youBirth | varchar(12) | NO | | NULL | |
| trgTIme | int(11) | NO | | NULL | |
+------------+------------------+------+-----+---------+----------------+
6 rows in set (0.02 sec)
mysql> drop table mymember
-> ;
Query OK, 0 rows affected (0.02 sec)
mysql> create table mymember1 select * from mymember;
mysql> create table mymember2 like mymember;
mysql> selecinsert into mymember3 select * from mymember;
mysql> ALTER TABLE mymember ADD youGender enum('m','w','x') default 'x' comment " 남성은m, 여성은w" AFTER youBirth;
Query OK, 0 rows affected (0.12 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> desc mymember;
+------------+-------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------+-------------------+------+-----+---------+----------------+
| myMemberID | int(10) unsigned | NO | PRI | NULL | auto_increment |
| youEmail | varchar(40) | NO | | NULL | |
| youName | varchar(12) | NO | | NULL | |
| youPass | varchar(20) | NO | | NULL | |
| youBirth | varchar(12) | NO | | NULL | |
| youGender | enum('m','w','x') | YES | | x | |
| trgTIme | int(11) | NO | | NULL | |
+------------+-------------------+------+-----+---------+----------------+
7 rows in set (0.00 sec)
alter table mymember02 modify youname int(20);
Query OK, 0 rows affected (0.06 sec)
Records: 0 Duplicates: 0 Warnings: 0
alter table mymember02 drop trgtime;
Query OK, 0 rows affected (0.06 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> INSERT INTO myMember(youEmail, youName, youPass, youBirth, youAge, youPhone, regTime)
VALUES('dnstjq6305@naver.com', '조운섭', 'qweasdf', '19911110', '32', '01024068904', '12345678');
Query OK, 1 row affected (0.00 sec)
mysql> SELECT * FROM myData;
+------------+----------------------+-------------+---------+----------+--------+---------+
| myMemberID | youEmail | youName | youPass | youBirth | youAge | regTime |
+------------+----------------------+-------------+---------+----------+--------+---------+
| 1 | jungsik321@naver.com | gentlemanjs | 1234 | 930209 | 30 | 327 |
+------------+----------------------+-------------+---------+----------+--------+---------+
1 row in set (0.00 sec)
mysql> SELECT * FROM mymember;
SELECT * FROM 테이블 명 where 조건;
SELECT * FROM mymember where memberID = 10;
SELECT * FROM mymember where memberID <> 10;
SELECT * FROM mymember where memberID >=5 and memberID <11;
SELECT * FROM myMember WHERE myMemberID = 6;
SELECT * FROM myMember WHERE MemberID NOT between 5 and 10;
SELECT * FROM myMember WHERE MemberID in(4, 6, 13, 14);
SELECT * FROM myMember WHERE youEmail like '%naver%';
SELECT * FROM myMember WHERE youEmail like 'web%';
SELECT * FROM myMember WHERE youEmail like '%com';
SELECT * FROM myMember WHERE youname like '김%';
SELECT * FROM myMember WHERE youname like '김%' OR youname like '황%';
SELECT * FROM myMember WHERE youname like '_근_';
SELECT * FROM myMember WHERE youname like '__연';
SELECT * FROM myMember WHERE youname IS NULL;
SELECT * FROM myMember WHERE youname IS NOT NULL;
SELECT * FROM myMember WHERE youAge >=30 or youname like '김%';
SELECT * FROM myMember WHERE youAge >=20 and youname like '김%';
SELECT * FROM myMember WHERE (memberID=2 or memberID=10) and youAge >= 30;
SELECT * FROM myMember LIMIT 12;
SELECT * FROM myMember LIMIT 5, 10;
SELECT youEmail FROM myMember LIMIT 5, 10;
SELECT * FROM myMember ORDER BY youAge DESC;
SELECT * FROM myMember ORDER BY youAge ASC;
UPDATE mymember SET youPass = "1234";
UPDATE mymember SET youPass = "1234567" WHERE memberID BETWEEN 5 AND 10;
UPDATE mymember SET youPass = "****" ORDER BY memberID DESC LIMIT 10;
DELETE FROM mymember;
DELETE FROM mymember WHERE memberID = 5;
DELETE FROM mymember WHERE youpass = '****';
DELETE FROM mymember ORDER BY youname LIMIT 5;
DELETE FROM mymember WHERE memberID IN(1, 9, 10);
SELECT m.youName, m.youEmail, r.youCont, r.regTime FROM myMember m JOIN myReview r ON(m.memberID = r.memberID);
+---------+-----------------------+-------------------------------+---------+
| youName | youEmail | youCont | regTime |
+---------+-----------------------+-------------------------------+---------+
| 박종호 | ik6623@naver.com | 정말 감사합니다. 너무 좋네요! | 12345 |
| 박성우 | seongwoo@lycos.com | 맛이 없어요. 여기 손절! | 12345 |
| 김정식 | jungsik321@naver.com | 사이즈 안맞아요. 극혐! | 12345 |
| 박근혁 | rmsgur2275@gmail.com | 정말 감사합니다. 너무 좋네요! | 12345 |
| 조운섭 | dnstjq6305@naver.com | 너무 아름답네요. 너무 좋네요! | 12345 |
| 이현우 | lhw1847@gmail.com | 정말 감사합니다. 너무 좋네요! | 12345 |
| 박근희 | sbxjs6999@naver.com | 정말 감사합니다. 너무 좋네요! | 12345 |
| 오세린 | dhtpfls321@naver.com | 너무 좋아요. 너무 좋네요! | 12345 |
| 김정식 | jungsik321@naver.com | 정말 감사합니다. 너무 좋네요! | 12345 |
| 황상연 | webstoryboy@naver.com | 감사합니다. 너무 좋네요! | 12345 |
+---------+-----------------------+-------------------------------+---------+
CREATE TABLE myMember (
memberID 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,
youAge int(20) NOT NULL,
youPhone int(20) NOT NULL,
regTime int(11) NOT NULL,
PRIMARY KEY (memberID)
) charset=utf8;
CREATE TABLE myReview (
reviewID int(10) unsigned auto_increment,
memberID int(40) unsigned,
youCont tinytext NOT NULL,
regTime int(11) NOT NULL,
PRIMARY KEY (reviewID)
) charset=utf8;
INSERT INTO myreview(memberID, youCont, regtime) values('4', '정말 감사합니다. 너무 좋네요!', '12345');
INSERT INTO myreview(memberID, youCont, regtime) values('8', '맛이 없어요. 여기 손절!', '12345');
INSERT INTO myreview(memberID, youCont, regtime) values('3', '사이즈 안맞아요. 극혐!', '12345');
INSERT INTO myreview(memberID, youCont, regtime) values('5', '정말 감사합니다. 너무 좋네요!', '12345');
INSERT INTO myreview(memberID, youCont, regtime) values('1', '너무 아름답네요. 너무 좋네요!', '12345');
INSERT INTO myreview(memberID, youCont, regtime) values('10', '정말 감사합니다. 너무 좋네요!', '12345');
INSERT INTO myreview(memberID, youCont, regtime) values('14', '정말 감사합니다. 너무 좋네요!', '12345');
INSERT INTO myreview(memberID, youCont, regtime) values('11', '너무 좋아요. 너무 좋네요!', '12345');
INSERT INTO myreview(memberID, youCont, regtime) values('3', '정말 감사합니다. 너무 좋네요!', '12345');
INSERT INTO myreview(memberID, youCont, regtime) values('2', '감사합니다. 너무 좋네요!', '12345');
SELECT m.youName, m.youEmail, r.youCont, r.regTime AS reviewTime FROM myMember m JOIN myReview r ON(m.memberID = r.memberID);
SELECT m.youName, m.youEmail, r.youCont, r.regTime FROM myMember m LEFT JOIN myReview r ON(m.memberID = r.memberID);
CREATE TABLE myrecode (
recodeID int(10) unsigned auto_increment,
memberID int(10) unsigned,
javascript tinyint NOT NULL,
html tinyint NOT NULL,
css tinyint NOT NULL,
mysql tinyint NOT NULL,
react tinyint NOT NULL,
PRIMARY KEY (recodeID)
) charset=utf8;
INSERT INTO MYRECODE(memberID, javascript, html, css, mysql, react) VALUES(1, 50, 30, 40, 30, 10);
INSERT INTO MYRECODE(memberID, javascript, html, css, mysql, react) VALUES(2, 60, 30, 40, 20, 10);
INSERT INTO MYRECODE(memberID, javascript, html, css, mysql, react) VALUES(3, 70, 30, 30, 30, 90);
INSERT INTO MYRECODE(memberID, javascript, html, css, mysql, react) VALUES(4, 10, 50, 60, 40, 10);
INSERT INTO MYRECODE(memberID, javascript, html, css, mysql, react) VALUES(5, 30, 30, 40, 50, 10);
INSERT INTO MYRECODE(memberID, javascript, html, css, mysql, react) VALUES(6, 40, 30, 90, 90, 80);
INSERT INTO MYRECODE(memberID, javascript, html, css, mysql, react) VALUES(7, 20, 30, 30, 30, 20);
INSERT INTO MYRECODE(memberID, javascript, html, css, mysql, react) VALUES(8, 70, 30, 50, 60, 10);
INSERT INTO MYRECODE(memberID, javascript, html, css, mysql, react) VALUES(9, 80, 10, 10, 30, 60);
INSERT INTO MYRECODE(memberID, javascript, html, css, mysql, react) VALUES(10, 90, 30, 20, 30, 10);
SELECT count(javascript) from myrecode;
SELECT sum(javascript) from myrecode;
SELECT avg(javascript) from myrecode;
SELECT max(javascript) from myrecode;
SELECT min(javascript) from myrecode;