MySQL은 가장 많이 사용되는 오픈 소스 관계형 데이터베이스 관리 시스템(RDBMS) 중 하나입니다.
MySQL은 가장 많이 사용되는 오픈 소스 관계형 데이터베이스 관리 시스템(RDBMS) 중 하나입니다. MySQL은 오픈 소스이며, 다양한 운영 체제에서 사용할 수 있습니다. MySQL은 일반적으로 웹 응용 프로그램, 데이터 분석 및 기업 응용 프로그램과 같은 다양한 분야에서 사용됩니다.
MySQL은 SQL(Structured Query Language)을 사용하여 데이터를 관리하며, 데이터를 효율적으로 저장, 검색, 수정 및 삭제할 수 있습니다. MySQL은 다중 사용자, 다중 스레드 및 다중 플랫폼 지원을 제공하여 대규모 응용 프로그램에서도 효과적으로 작동할 수 있습니다.
MySQL은 자유롭게 사용할 수 있으며, 다양한 커뮤니티 및 개발자가 지속적으로 업데이트와 개선을 진행하고 있습니다. MySQL은 또한 라이선스 비용이 없어서 비용 효율적인 데이터베이스 솔루션으로 인기가 있습니다.
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> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.02 sec)
mysql> create database sample01;
Query OK, 1 row affected (0.01 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sample01 |
| sys |
+--------------------+
5 rows in set (0.00 sec)
use sample01;
Database changed
mysql> mysql> drop database sample01;
Query OK, 0 rows affected (0.03 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
create table members(
memberID int(10) unsigned auto_increment,
youEmail varchar(40) NOT NULL,
youName varchar(10) NOT NULL,
youPass varchar(20) NOT NULL,
youBirth int(10) NOT NULL,
youAge int(5) NOT NULL,
regTime int(30) NOT NULL,
PRIMARY KEY(memberID)
) charset=utf8;
create table reviews(
reviewID int(10) unsigned auto_increment,
memberID int(10) unsigned,
youText tinytext NOT NULL,
regTime int(30) NOT NULL,
PRIMARY KEY(reviewID)
) charset=utf8;
mysql> show tables;
+--------------------+
| Tables_in_sample01 |
+--------------------+
| member |
+--------------------+
1 row in set (0.00 sec)
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 | |
| youAge | int(5) | NO | | NULL | |
| regTime | int(20) | NO | | NULL | |
+------------+------------------+------+-----+---------+----------------+
7 rows in set (0.01 sec)
mysql> drop table nember;
ERROR 1051 (42S02): Unknown table 'sample01.nember'
mysql> drop table member;
Query OK, 0 rows affected (0.03 sec)
mysql> truncate table member;
insert into
테이블 명(필드명) values
INSERT INTO members(youEmail, youName, youPass, youBirth, youAge, regTime) VALUES("webstoryboy@naver.com","황상연","1234","19990304","26","03140316");
INSERT INTO members(youEmail, youName, youPass, youBirth, youAge, regTime) VALUES("dlscks0930@naver.com","황인찬","1234","19980930","26","03140316");
INSERT INTO members(youEmail, youName, youPass, youBirth, youAge, regTime) VALUES("gp2617@naver.com","천설희","1234","19950313","29","03140316");
INSERT INTO members(youEmail, youName, youPass, youBirth, youAge, regTime) VALUES("dsy1943@naver.com","여다슬","1943","20011227","23","03140316");
INSERT INTO members(youEmail, youName, youPass, youBirth, youAge, regTime) VALUES("1346zany@gmail.com","이승연","1234","19991216","25","03140316");
INSERT INTO members(youEmail, youName, youPass, youBirth, youAge, regTime) VALUES("ebmdols@naver.com","장진용","1234","19940401","26","03140316");
INSERT INTO members(youEmail, youName, youpass, youBirth, youAge, regTime) VALUES("jo0132@naver.com","노지영","1234","19950323","29","03140316");
INSERT INTO members(youEmail, youName, youPass, youBirth, youAge, regTime) VALUES("skadldldl123@gmail.com","안교남","1234","19920923","32","03140316");
INSERT INTO members(youEmail, youName, youPass, youBirth, youAge, regTime) VALUES("ehcjswo1@gmail.com","김도현","123","19951003","29","03140316");
INSERT INTO members(youEmail, youName, youPass, youBirth, youAge, regTime) VALUES("goed0522@gmail.com","변우현","1234","20000629","24","03141516");
INSERT INTO members(youEmail, youName, youPass, youBirth, youAge, regTime) VALUES("yuna243441@naver.com","이유나","1234","20020508","22","03140316");
INSERT INTO members(youEmail, youName, youPass, youBirth, youAge, regTime) VALUES("im.kebab00@gmail.com","이요셉","1234","19990315","26","03140316");
INSERT INTO members(youEmail, youName, youpass, youBirth, youAge, regTime) VALUES("ture403@gmail.com","전윤기","1234","19920210","32","03140316");
INSERT INTO members(youEmail, youName, youPass, youBirth, youAge, regTime) VALUES("dongjin6539@naver.com","신동진","1234","19960709","28","03140316");
INSERT INTO members(youEmail, youName, youPass, youBirth, youAge, regTime) VALUES("gnsrbdi@naver.com","이훈규","1234","19950227","29","03140316");
INSERT INTO members(youEmail, youName, youPass, youBirth, youAge, regTime) VALUES("jeongyouna_@naver.com","정유나","1234","19950606","29","03140316");
INSERT INTO members(youEmail, youName, youPass, youBirth, youAge, regTime) VALUES("daanbi1345@gmail.com","조은경","1234","19930205","31","03140316");
INSERT INTO members(youEmail, youName, youPass, youBirth, youAge, regTime) VALUES("hunmi961119@gmail.com","진현미","1234","19961119","28","03140316");
INSERT INTO members(youEmail, youName, youPass, youBirth, youAge, regTime) VALUES("getgrovy@gmail.com","정희석","1234","19990101","26","03140316");
INSERT INTO members(youEmail, youName, youPass, youBirth, youAge, regTime) VALUES("kshkmn0929@naver.com","김도현","0929","20020929","22","03140316");
INSERT INTO members(youEmail, youName, youPass, youBirth, youAge, regTime) VALUES("hyejeong3283@gmail.com","이혜정","1234","19940622","30","03140316");
INSERT INTO members(youEmail, youName, youPass, youBirth, youAge, regTime) VALUES("didrn94553@gmail.com","이양구","1234","19941212","30","03140316");
INSERT INTO members(youEmail, youName, youPass, youBirth, youAge, regTime) VALUES("ghkddn132@naver.com","정황우","1234","19970130","25","03140316");
INSERT INTO members(youEmail, youName, youPass, youBirth, youAge, regTime) VALUES("esansi@naver.com","김현빈","1234","19970524","27","03140316");
INSERT INTO members(youEmail, youName, youPass, youBirth, youAge, regTime) VALUES("lee3ll@naver.com","이은지","1234","19930311","31","03140316");
INSERT INTO members(youEmail, youName, youPass, youBirth, youAge, regTime) VALUES("dripidea77@gmail.com","김시연","1234","19930313","31","03140316");
INSERT INTO members(youEmail, youName, youPass, youBirth, youAge, regTime) VALUES("itshena01@gmail.com","조한미","1234","19930211","31","03140316");
INSERT INTO members(youEmail, youName, youPass, youBirth, youAge, regTime) VALUES("aimee00418@gmail.com","권현정","1234","19830211","39","03140316");
insert into
테이블 명(필드명)
INSERT INTO reviews(memberId, youText, regTime) VALUES("4","정말 감사합니다." ,"1234567");
INSERT INTO reviews(memberId, youText, regTime) VALUES("14","별로네요 잘 봤어요" ,"23456");
INSERT INTO reviews(memberId, youText, regTime) VALUES("2","이건 정말 사야합니다." ,"4321");
INSERT INTO reviews(memberId, youText, regTime) VALUES("5","내용이 좋네요.", "76543");
INSERT INTO reviews(memberId, youText, regTime) VALUES("7","정말 감사합니다. 또올께요" ,"988567");
INSERT INTO reviews(memberId, youText, regTime) VALUES("1","멋진 내용입니다." ,"43536");
INSERT INTO reviews(memberId, youText, regTime) VALUES("9","정말 감사합니다. 다신 안와요", "67342");
INSERT INTO reviews(memberId, youText, regTime) VALUES("4","아전 별루", "35326");
INSERT INTO reviews(memberId, youText, regTime) VALUES("2","이건 사기에 아까워요", "57768");
INSERT INTO reviews(memberId, youText, regTime) VALUES("7","사기꾼 돈내놔!!", "164546");
select
필드명 from
테이블명 where
조건SELECT * FROM member;
SELECT * FROM member WHERE memberID=1;
SELECT * FROM member WHERE memberID= <> 1;
SELECT * FROM member WHERE memberID >=5 AND memberID <=10;
SELECT * FROM member WHERE youAge BETWEEN 30 AND 40;
SELECT * FROM member WHERE youAge NOT BETWEEN 30 AND 40;
SELECT * FROM member WHERE memberID IN(1,5,10,15);
SELECT * FROM member WHERE youname is null;
SELECT * FROM member WHERE youname is not null;
SELECT * FROM member WHERE youname LIKE '%연%';
SELECT * FROM member WHERE youname LIKE '김%';
SELECT * FROM member WHERE youname LIKE '%현';
SELECT * FROM member WHERE youname LIKE '_상_';
SELECT * FROM member WHERE youname LIKE '김%' OR youname LIKE '이%';
SELECT youName FROM member;
SELECT youName FROM member ORDER BY youname asc;
SELECT youName FROM member ORDER BY youname desc;
SELECT count(youemail) FROM member;
SELECT
youname,youage FROM member;
SELECT youname,youage FROM member WHERE youage >=30;
SELECT youname FROM member WHERE youname like "김%" and youage >= 25;
SELECT youname FROM member WHERE youname like "김%" or youage >= 25;
SELECT * FROM member WHERE (memberID =2 OR memberID = 9) and youAge >= 25;
SELECT * FROM member where memberID in ('9','2') and youAge >= 25;
SELECT * FROM member LIMIT 5;
SELECT * FROM member LIMIT 5, 5;
SELECT youEmail FROM member LIMIT 10, 10;
SELECT DISTINCT youage FROM member;
update
테이블명 set
컬럼명 조건UPDATE member SET youpass = "1234";
UPDATE member SET youpass = "9999" WHERE memberid = "3";
UPDATE member SET youpass = "9999" WHERE memberid BETWEEN 5 AND 10;
delete
from
테이블명 where
조건DELETE FROM member WHERE memberid = "5";
DELETE FROM member WHERE youpass = "1234";
DELETE FROM member ORDER BY memberid LIMIT 5;
DELETE FROM member WHERE memberid IN(11,13,15);
ALTER TABLE members ADD youPhone varchar(20) NOT NULL;
Query OK, 0 rows affected (0.08 sec)
Records: 0 Duplicates: 0 Warnings: 0
ALTER TABLE members ADD youPhone varchar(20) NOT NULL AFTER youAge;
Query OK, 0 rows affected (0.08 sec)
Records: 0 Duplicates: 0 Warnings: 0
alter table members modify youPhone int(20) NOT NULL;
Query OK, 0 rows affected (0.09 sec)
Records: 0 Duplicates: 0 Warnings: 0
alter table members drop youPhone;
Query OK, 0 rows affected (0.08 sec)
Records: 0 Duplicates: 0 Warnings: 0
select m.youEmail, m.youname, r.youtext, r.regtime from members m JOIN reviews r on (m.memberid = r.memberid);
select m.youEmail, m.youname, r.youtext, r.regtime AS reviewRegTime from members m JOIN reviews r on (m.memberid = r.memberid);
select m.youEmail, m.youname, r.youtext, r.regtime from members m LEFT JOIN reviews r on (m.memberid = r.memberid);
CREATE TABLE schoolRecode (
studentID int(10) unsigned NOT NULL AUTO_INCREMENT comment "학생번호",
class tinytext comment "소속클래스(반)",
english tinytext NOT NULL comment "영어점수",
math tinytext NOT NULL comment "수학점수",
science tinytext NOT NULL comment "과학점수",
coding tinytext NOT NULL comment "코딩점수",
PRIMARY KEY(studentID)
) charset=utf8;
INSERT INTO schoolRecode(english, math, science, coding) VALUES(50, 10, 20, 100);
INSERT INTO schoolRecode(class, english, math, science, coding) VALUES(1, 50, 10, 20, 100);
INSERT INTO schoolRecode(class, english, math, science, coding) VALUES(2, 40, 30, 22, 90);
INSERT INTO schoolRecode(class, english, math, science, coding) VALUES(2, 50, 40, 23, 80);
INSERT INTO schoolRecode(class, english, math, science, coding) VALUES(3, 60, 50, 24, 70);
INSERT INTO schoolRecode(class, english, math, science, coding) VALUES(4, 70, 60, 25, 60);
INSERT INTO schoolRecode(class, english, math, science, coding) VALUES(5, 80, 70, 26, 50);
select count(class) from schoolrecode;
select count(*) from schoolrecode;
select count(*) from schoolrecode;
select sum(coding) from schoolrecode;
select sum(coding) from schoolrecode where studentid >=1 and studentId <=4;
select max(coding) from schoolrecode
select min(coding) from schoolrecode
select avg(coding) from schoolrecode
select class, avg(english) from schoolrecode where class in(1,2,3,4,5) GROUP BY class;
select class, sum(math) from schoolrecode where class in(1,2,3,4,5) GROUP BY class;
select class, sum(math) from schoolrecode where class in(1,2,3,4,5) GROUP BY class having sum(math) >=70;
select studentID, english from schoolrecode order by english desc;
select studentID, english from schoolrecode order by english asc;
SELECT class, SUM(math) FROM schoolRecode WHERE class IN(1,2,3,4,5) GROUP BY class ORDER BY sum(math) DESC;