๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ

MySQL

by Youcodein 2022. 9. 15.
728x90
๋ฐ˜์‘ํ˜•

MySQL์€ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ์†Œํ”„ํŠธ์›จ์–ด์ž…๋‹ˆ๋‹ค. ์ผ๋ฐ˜์ ์œผ๋กœ ๋ฐ์ดํ„ฐ๋ฅผ ์ถ”๊ฐ€ํ•˜๊ฑฐ๋‚˜ ๊ฒ€์ƒ‰, ์ถ”์ถœํ•˜๋Š” ๊ธฐ๋Šฅ์„ ๋ชจ๋‘ ํฌํ•จํ•ด์„œ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค๋ผ๊ณ  ๋ถ€๋ฆ…๋‹ˆ๋‹ค.

MySQL์€ ์„ธ๊ณ„์—์„œ ๊ฐ€์žฅ ๋งŽ์ด ์“ฐ๋Š” ์˜คํ”ˆ ์†Œ์Šค์˜ ๊ด€๊ณ„ํ˜• ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ๊ด€๋ฆฌ์‹œ์Šคํ…œ(RDBMS)์ž…๋‹ˆ๋‹ค.
MySQL์€ PHP ์Šคํฌ๋ฆฝํŠธ ์–ธ์–ด์™€ ์ƒํ˜ธ ์—ฐ๋™์ด ์ž˜ ๋˜๋ฉด์„œ ์˜คํ”ˆ์†Œ์Šค๋ฅผ ๊ฐœ๋ฐœ๋œ ๋ฌด๋ฃŒ ํ”„๋กœ๊ทธ๋žจ์ž…๋‹ˆ๋‹ค.
๊ทธ๋ž˜์„œ ํ™ˆํŽ˜์ด์ง€๋‚˜ ์‡ผํ•‘๋ชฐ(์›Œ๋“œํ”„๋ ˆ์Šค, Cafe24, ์ œ๋กœ๋ณด๋“œ ๊ทธ๋ˆ„๋ณด๋“œ)๋“ฑ ์ผ๋ฐ˜์ ์œผ๋กœ ์›น ๊ฐœ๋ฐœ์— ๋„๋ฆฌ ์‚ฌ์šฉํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.

MAMP๋ž€ ์›น์‚ฌ์ดํŠธ๋ฅผ ๊ฐœ๋ฐœํ•  ๋•Œ ์“ฐ์ด๋Š” ๊ธฐ์ˆ  ์Šคํƒ์ธ macOS, Apache, MySQL, PHP ์˜ ์•ฝ์–ด์ด์ž ์†”๋ฃจ์…˜ ์Šคํƒ์ด๋‹ค.
http://www.mamp.info/en/downlads/
์œˆ๋„์šฐ : cd MAMP/bin//mysql/bin
๋กœ๊ทธ์ธ : 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/Libary/bin
๋กœ๊ทธ์ธ : ./mysql -uroot -proot
webstoryboyhwang@Webstoryboyui-MacBookPro 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 188
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 sample02;
Query OK, 1 row affected (0.00 sec)
show databases;
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sample01           |
| sample02           |
| sys                |
+--------------------+
6 rows in set (0.00 sec)
use ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ์ด๋ฆ„;
mysql> use sample01;
Database changed
drop database ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ์ด๋ฆ„;
mysql> drop database sample02;
Query OK, 0 rows affected (0.03 sec)
create table ํ…Œ์ด๋ธ” ์ด๋ฆ„;
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;
show tables;
mysql> show tables;
+--------------------+
| Tables_in_sample01 |
+--------------------+
| member             |
+--------------------+
1 row in set (0.00 sec)
decs ํ…Œ์ด๋ธ” ์ด๋ฆ„;
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.01 sec)
drop table ํ…Œ์ด๋ธ” ์ด๋ฆ„;
mysql> drop table member;
Query OK, 0 rows affected (0.01 sec)

INSERT INTO ํ…Œ์ด๋ธ”์ด๋ฆ„(ํ•„๋“œ๋ช…) VALUE(๋ฐ์ดํ„ฐ);

INSERT INTO member(youEmail, youName, youPass, youBirth, regTime) VALUES('***@gmail.com', 'ํ™ฉ**', '1234', '19******', '1234567')
INSERT INTO member(youEmail, youName, youPass, youBirth, regTime) VALUES('***@naver.com', '๊น€**', '1234', '19******', '04')
INSERT INTO member(youEmail, youName, youPass, youBirth, regTime) VALUES('***@naver.com','๊ถŒ**','1234','19******','1234567');
INSERT INTO member(youEmail, youName, youPass, youBirth, regTime) VALUES('***@gmail.com', '๋ฌธ**', '1234', '19******', '1234567');
INSERT INTO member(youEmail, youName, youPass, youBirth, regTime) VALUES('***@gmail.com','์ด**','1234','19******','1234567');
INSERT INTO member(youEmail, youName, youPass, youBirth, regTime) VALUES('***@gmail.com','๊ถŒ**','1234','19******','1234567');
INSERT INTO member(youEmail, youName, youPass, youBirth, regTime) VALUES('***@gmail.com','์ „**','1234','19******','1234567');
INSERT INTO member(youEmail, youName, youPass, youBirth, regTime) VALUES('***@naver.com','๊น€**','1234','19******','1234567')
INSERT INTO member(youEmail, youName, youPass, youBirth, regTime) VALUES('***@gmail.com', '๊น€**', '1234', '20******','1234567');
INSERT INTO member(youEmail, youName, youPass, youBirth, regTime) VALUES('***@naver.com','์ด**','1234','19******','1234567')
INSERT INTO member(youEmail, youName, youPass, youBirth, regTime) VALUES('***3@naver.com', '๊น€**', '1234', '19******', '1234567');
SELECT ํ•„๋“œ๋ช… FROM ํ…Œ์ด๋ธ”๋ช… WHERE ์กฐ๊ฑด

์ „์ฒด ๋ฐ์ดํ„ฐ ๋ถˆ๋Ÿฌ์˜ค๊ธฐ

mysql> SELECT * FROM member;
+------------+--------------------------+---------+---------+----------+----------+
| myMemberID | youEmail                 | youName | youPass | youBirth | regTime  |
+------------+--------------------------+---------+---------+----------+----------+
|          1 | ****@gmail.com           | ํ™ฉ**    | 1234    | 19****** |  1234567 |
|          2 | ****@naver.com           | ๋ฐ•**    | 1234    | 19****** |  1234567 |
|          3 | ****@naver.com           | ๊น€**    | 1234    | 19****** |        4 |
|          4 | ****@gmail.com           | ๊ฐ•**    | 1234    | 19****** |  1234567 |
|          5 | ****@gmail.com           | ๋ฐ•**    | 1234    | 19****** |  1234567 |
|          6 | ****@gmail.com           | ์ด**    | 1234    | 19****** |  1234567 |
|          7 | ****@gmail.com           | ๊น€**    | 1234    | 19****** |  1234567 |
|          8 | ****@naver.com           | ์—ฌ**    | 1234    | 22****** | 12324567 |
|          9 | ****@naver.com           | ์ตœ**    | 3950    | 20****** |  1234567 |
|         10 | ****@gmail.com           | ์ „**    | 1234    | 19****** |  1234567 |
|         11 | ****@gmail.com           | ๊ถŒ**    | 1234    | 19****** |  1234567 |
|         12 | ****@gmail.com           | ๋ฌธ**    | 1234    | 19****** |  1234567 |
|         13 | ****@naver.com           | ๊ถŒ**    | 1234    | 19****** |  1234567 |
|         14 | ****@naver.com           | ๊น€**    | 1234    | 19****** |        4 |
|         15 | ****@gmail.com           | ์ด**    | 1234    | 19****** |  1234567 |
|         16 | ****@naver.com           | ๊น€**    | 1234    | 19****** |  1234567 |
|         17 | ****@naver.com           | ์†ก**    | 1234    | 19****** |  1234567 |
|         18 | ****@naver.com           | ๊น€**    | 1234    | 19****** |  1234567 |
|         19 | ****@naver.com           | ๊น€**    | 1234    | 19****** |  1234567 |
|         20 | ****@naver.com           | ์ •**    | 1234    | 19****** |  1234567 |
|         21 | ****@gmail.com           | ๊น€**    | 1234    | 20****** |  1234567 |
|         22 | ****@naver.com           | ์ด**    | 1234    | 19****** |  1234567 |
|         23 | ****@naver.com           | ๊น€**    | 1234    | 19****** |  1234567 |
+------------+--------------------------+---------+---------+----------+----------+
23 rows in set (0.00 sec)

myMemberID๊ฐ€ 6๋ฒˆ์ธ ๊ฒฝ์šฐ

mysql> SELECT * FROM member WHERE myMemberID = 6;
+------------+----------------------+---------+---------+----------+---------+
| myMemberID | youEmail             | youName | youPass | youBirth | regTime |
+------------+----------------------+---------+---------+----------+---------+
|          6 | **********@gmail.com | ์ด**    | 1234    | 19****** | 1234567 |
+------------+----------------------+---------+---------+----------+---------+
1 row in set (0.01 sec)

Email ์ค‘์— naver ํ…์ŠคํŠธ๋ฅผ ํฌํ•จํ•˜๊ณ  ์žˆ๋Š” ๊ฒฝ์šฐ

mysql> SELECT * FROM member WHERE youEmail LIKE '%naver%';
+------------+------------------------+---------+---------+----------+----------+
| myMemberID | youEmail               | youName | youPass | youBirth | regTime  |
+------------+------------------------+---------+---------+----------+----------+
|          2 | ****@naver.com         | ๋ฐ•**  | 1234      | 19****** |  1234567 |
|          3 | ****@naver.com         | ๊น€**  | 1234      | 19****** |        4 |
|          8 | ****@naver.com         | ์—ฌ**  | 1234      | 22****** | 12324567 |
|          9 | ****@naver.com         | ์ตœ**  | 3950      | 20****** |  1234567 |
|         13 | ****@naver.com         | ๊ถŒ**  | 1234      | 19****** |  1234567 |
|         14 | ****@naver.com         | ๊น€**  | 1234      | 19****** |        4 |
|         16 | ****@naver.com         | ๊น€**  | 1234      | 19****** |  1234567 |
|         17 | ****@naver.com         | ์†ก**  | 1234      | 19****** |  1234567 |
|         18 | ****@naver.com         | ๊น€**  | 1234      | 19****** |  1234567 |
|         19 | ****@naver.com         | ๊น€**  | 1234      | 19****** |  1234567 |
|         20 | ****@naver.com         | ์ •**  | 1234      | 19****** |  1234567 |
|         22 | ****@naver.com         | ์ด**  | 1234      | 19****** |  1234567 |
|         23 | ****@naver.com         | ๊น€**  | 1234      | 19****** |  1234567 |
+------------+------------------------+---------+---------+----------+----------+
13 rows in set (0.00 sec)


728x90
๋ฐ˜์‘ํ˜•

๋Œ“๊ธ€