MySQL은 데이터베이스 소프트웨어입니다. 일반적으로 데이터를 추가하거나 검색, 추출하는 기능을 모두 포함해서 데이터베이스라고 부릅니다.
MySQL은 세계에서 가장 많이 쓰이는 오픈 소스의 관계형 데이터베이스 관리 시스템(RDBMS)입니다. MySQL은 PHP 스크립트 언어와 상호 연동이 잘 되면서 오픈소스로 개발된 무료 프로그램입니다. 그래서 홈페이지나 쇼핑몰(워드프레서, cafe24, 제로보드, 그누보드) 등 일반적으로 웹 개발에 널리 사용하고 있습니다.
//먼저 MAMP 켰는지 확인
C:\Users\line> cd c:₩
C:₩> cd MAMP/bin/mysql/bin
C:₩MAMP₩bin₩mysql₩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 5
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>
MacBook-Air ~ % cd /Applications/MAMP/Library/bin
MacBook-Air bin % sudo ./mysql -uroot -p
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 186
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.
mysql> create database sample;
Query OK, 1 row affected (0.00 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sample |
+--------------------+
5 rows in set (0.00 sec)
mysql> use sample;
Database changed
mysql> drop database sample;
Query OK, 0 rows affected (0.00 sec)
mysql> CREATE TABLE myData (
myMemberID int(10) unsigned auto_increment comment "회원의 고유번호",
youEmail varchar(40) NOT NULL comment "회원 아이디",
youName varchar(12) NOT NULL comment "회원 이름",
youPass varchar(20) NOT NULL comment "회원 비밀번호",
youBirth varchar(12) NOT NULL comment "회원 생일",
youAge varchar(12) NOT NULL comment "회원 나이",
regTime int(11) NOT NULL comment "회원 가입 시간",
PRIMARY KEY (myMemberID)
) charset=utf8 comment "회원 정보 테이블";
Query OK, 0 rows affected (0.04 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_tast01 |
+------------------+
| mydata |
+------------------+
1 row in set (0.00 sec)
mysql> desc myData;
+------------+------------------+------+-----+---------+----------------+
| 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 | |
| youAge | varchar(12) | NO | | NULL | |
| regTime | int(11) | NO | | NULL | |
+------------+------------------+------+-----+---------+----------------+
7 rows in set (0.00 sec)
mysql> drop table myMember;
Query OK, 0 rows affected (0.01 sec)
mysql> create table myMember1 SELECT*FROM myMember;
mysql> create table myMember2 LIKE myMember;
mysql> INSERT INTO myMember3 SELECT*FROM myMember1;
INSERT INTO myMember(youEmail, youName, youPass, youBirth, youAge, youPhone, regTime) VALUES('webstoryboy@naver.com','황상연','12dfsdecv','19920405','33','01039858583','578365839');
INSERT INTO myMember(youEmail, youName, youPass, youBirth, youAge, youPhone, regTime) VALUES('jungsik321@naver.com', '김정식', '1234', '19930209', '30', '01025738580', '20220314');
INSERT INTO myMember(youEmail, youName, youPass, youBirth, youAge, youPhone, regTime) VALUES('ik6623@naver.com','박종호','1234qwer','19950909','28','01040976623','10293857');
INSERT INTO myMember(youEmail, youName, youPass, youBirth, youAge, youPhone, regTime) VALUES('rmsgur2275@gmail.com','박근혁','alcls2860','19980611','25','01058122860', '12345678');
INSERT INTO myMember(youEmail, youName, youPass, youBirth, youAge, youPhone, regTime) VALUES('apdlvmf8044@gmail.com', '송준섭', 'qweasdf', '19931120', '30', '01088648044', '21846351');
INSERT INTO myMember(youEmail, youName, youPass, youBirth, youAge, youPhone, regTime) VALUES('sbxjs6999@naver.com','박근희','1234qwer','19970214','28',01041046999,'12345678');
INSERT INTO myMember(youEmail, youName, youPass, youBirth, youAge, youPhone, regTime) VALUES('seongwoo@lycos.com','박성우','123456asd','19910506','32', '01044779156','54216451');
INSERT INTO myMember(youEmail, youName, youPass, youBirth, youAge, youPhone, regTime) VALUES('dnwls7738@naver.com','천우진', '12asdf', '19960324', '27', '01055805274', '45678941');
INSERT INTO myMember(youEmail, youName, youPass, youBirth, youAge, youPhone, regTime) VALUES('dnstjq6305@naver.com', '조운섭', 'qweasdf', '19911110', '32', '01024068904', '12345678');
INSERT INTO myMember(youEmail, youName, youPass, youBirth, youAge, youPhone, regTime) VALUES('lhw1847@gmail.com','이현우','1234','19971221','26', '01055332287', '0303');
INSERT INTO myMember(youEmail, youName, youPass, youBirth, youAge, youPhone, regTime) VALUES('dhtpfls321@naver.com', '오세린', '1234', '19980214', '25', '01032229944', '12345678');
INSERT INTO myMember(youEmail, youName, youPass, youBirth, youAge, youPhone, regTime) VALUES('GarenChoi@naver.com','최근영','1234','19970117','26','01054651345','234');
INSERT INTO myMember(youEmail, youName, youPass, youBirth, youAge, youPhone, regTime) VALUES('sna12345@naver.com', '배석찬','1234','19960727','27','01033125279','03270327');
INSERT INTO myMember(youEmail, youName, youPass, youBirth, youAge, youPhone, regTime) VALUES('sbxjs6999@naver.com','박근희','1234qwer','19970214','26',01041046999,'12345678');
INSERT INTO myMember(youEmail, youName, youPass, youBirth, youAge, youPhone, regTime) VALUES('wwuu123@naver.com','최가영','12345678','19970506','26','01066179991','12345678');
INSERT INTO myMember(youEmail, youName, youPass, youBirth, youAge, youPhone, regTime) VALUES('illie@naver.com', '류성일', 'ryuPass', '19940426', '29', '01055327391', '1440');
INSERT INTO myMember(youEmail, youName, youPass, youBirth, youAge, youPhone, regTime) VALUES('jsjh442@naver.com','박지선','1234','19980423','25','01057421662','12341234');
INSERT INTO myMember(youEmail, youName, youPass, youBirth, youAge, youPhone, regTime) VALUES('ohwehoh@naver.com','이연우','dldus1358','19950720','28','01014141441','12341234');
INSERT INTO myMember(youEmail, youName, youPass, youBirth, youAge, youPhone, regTime) VALUES('go_goa@naver.com' ,'김현우', '159753', '19920126', '31', '01087361836', '40250371');
INSERT INTO myMember(youEmail, youName, youPass, youBirth, youAge, youPhone, regTime) VALUES('placidcy@gmail.com', '김지섭', '1234', '19900212', '32', '01011112222','20220314');
mysql> ALTER TABLE myData MODIFY youGender int(20);
Query OK, 10 rows affected (0.04 sec)
Records: 10 Duplicates: 0 Warnings: 0
mysql> desc myData;
+------------+------------------+------+-----+---------+----------------+
| 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 | |
| youAge | varchar(12) | NO | | NULL | |
| youGender | int(20) | YES | | NULL | |
| regTime | int(11) | NO | | NULL | |
+------------+------------------+------+-----+---------+----------------+
8 rows in set (0.00 sec)
ALTER TABLE myData DROP youGender;
Query OK, 0 rows affected (0.08 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> desc myData;
+------------+------------------+------+-----+---------+----------------+
| 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 | |
| youAge | varchar(12) | NO | | NULL | |
| regTime | int(11) | NO | | NULL | |
+------------+------------------+------+-----+---------+----------------+
7 rows in set (0.00 sec)
INSERT INTO myData(youEmail, youName, youPass, youBirth, youAge, youPhone, regTime) VALUES('wwuu123@naver.com','최가영','12345678','19970506','26','01066179991','12345678');
mysql> SELECT*FROM myMember;
SELECT * FROM myMember WHERE MemberID = 10;
SELECT * FROM myMember WHERE MemberID <> 10;
SELECT * FROM myMember WHERE MemberID >=5 and MemberID <=10;
SELECT * FROM myMember WHERE MemberID BETWEEN 5 AND 10;
SELECT * FROM myMember WHERE NOT MemberID BETWEEN 5 AND 10;
SELECT * FROM myMember WHERE NOT MemberID IN(4,5,13,14);
SELECT * FROM myMember WHERE youEmail LIKE '%naver%';
SELECT * FROM myMember WHERE youEmail LIKE 'wed%';
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 youAge >=30 || youName LIKE '김%';
SELECT * FROM myMember WHERE youAge >=20 && 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 = '1234' WHERE boardID = 3;
UPDATE myMember SET youPass = '1234567' where memberID BETWEEN 5 and 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(8,9,10);
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(10) unsigned,
youCont tinytext NOT NULL,
regTime int(11) NOT NULL,
PRIMARY KEY (reviewID)
) charset=utf8;
INSERT INTO myReview(memberID, youCont, regTime) VALUES('1','너무 좋네요','1234');
INSERT INTO myReview(memberID, youCont, regTime) VALUES('2','ㅇㄴㅁ너무 좋네요','1234');
INSERT INTO myReview(memberID, youCont, regTime) VALUES('3','너ㄴㅇㅁㄴ무 좋네요','1234');
INSERT INTO myReview(memberID, youCont, regTime) VALUES('4','너ㅇㅁㄴㅇㅁㄴㅇ무 좋네요','1234');
INSERT INTO myReview(memberID, youCont, regTime) VALUES('5','너무ㄴㅇㅁ 좋네요','1234');
INSERT INTO myReview(memberID, youCont, regTime) VALUES('6','너무ㅇㅁㄴ 좋네요','1234');
INSERT INTO myReview(memberID, youCont, regTime) VALUES('7','너무 좋ㅇㄴㅁㅇ네요','1234');
INSERT INTO myReview(memberID, youCont, regTime) VALUES('8','너무ㅇㅁㄴ 좋네요','1234');
INSERT INTO myReview(memberID, youCont, regTime) VALUES('9','너무 ㅇㅁㄴ좋네요','1234');
INSERT INTO myReview(memberID, youCont, regTime) VALUES('10','너무 ㅇㄴㅁ','1234');
INSERT INTO myreview(memberID, youCont, regTime) VALUES('4', '정말 감사합니다. 너무 좋네요!', '12345');
INSERT INTO myreview(memberID, youCont, regTime) VALUES('7', '이거 정말 사야돼!!', '12345');
INSERT INTO myreview(memberID, youCont, regTime) VALUES('1', '이거 가방 오나전 별루예요.. 사진빨', '12345');
INSERT INTO myreview(memberID, youCont, regTime) VALUES('9', '이거 좋다! 좋다! 좋다!', '12345');
INSERT INTO myreview(memberID, youCont, regTime) VALUES('12', '마라탕 먹고싶다.', '12345');
INSERT INTO myreview(memberID, youCont, regTime) VALUES('3', '오늘은 정말 마라탕 먹고싶다.', '12345');
INSERT INTO myreview(memberID, youCont, regTime) VALUES('16', '가성비 짱입니다. 당장 사세요.', '12345');
INSERT INTO myreview(memberID, youCont, regTime) VALUES('19', '안녕하세요. 안녕하세요.', '12345');
INSERT INTO myreview(memberID, youCont, regTime) VALUES('2', '안녕못해요. 안녕못해요.', '12345');
INSERT INTO myreview(memberID, youCont, regTime) VALUES('14', '빨리빨리빨리.', '12345');
SELECT m.youName, m.youEmail, r.youCont, r.regTime FROM myMember m JOIN myReview r ON(m.memberID = r.memberID);
SELECT m.youName, m.youEmail, r.youCont AS regTime 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, 40, 10, 20, 10, 20);
INSERT INTO myRecode(memberID, javascript, html, css, mysql, react) VALUES(3, 50, 70, 60, 50, 30);
INSERT INTO myRecode(memberID, javascript, html, css, mysql, react) VALUES(4, 60, 40, 50, 70, 10);
INSERT INTO myRecode(memberID, javascript, html, css, mysql, react) VALUES(5, 70, 60, 40, 30, 20);
INSERT INTO myRecode(memberID, javascript, html, css, mysql, react) VALUES(6, 80, 30, 60, 30, 30);
INSERT INTO myRecode(memberID, javascript, html, css, mysql, react) VALUES(7, 90, 30, 40, 50, 10);
INSERT INTO myRecode(memberID, javascript, html, css, mysql, react) VALUES(8, 10, 90, 40, 10, 10);
INSERT INTO myRecode(memberID, javascript, html, css, mysql, react) VALUES(9, 10, 20, 40, 40, 10);
INSERT INTO myRecode(memberID, javascript, html, css, mysql, react) VALUES(10, 30, 10, 90, 70, 60);
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;
SELECT count(javascript) FROM myRecode;