카테고리 없음

MySQL을 cmd에서 사용해 보기!

진블로그 2023. 3. 13. 22:19
728x90
반응형

MySQL

MySQL은 오픈 소스 관계형 데이터베이스 관리 시스템(RDBMS)입니다.

MySQL은 다중 사용자, 다중 스레드 RDBMS로서, 데이터의 안정성과 보안성을 제공합니다. MySQL은 대부분의 운영 체제에서 작동하며, 웹 애플리케이션 개발, 데이터 분석, 빅 데이터, 클라우드 기반 애플리케이션 등에 많이 사용됩니다.
MySQL은 SQL(Structured Query Language)을 사용하여 데이터를 관리합니다. SQL은 데이터베이스에 저장된 데이터를 조작하기 위한 표준적인 언어로서, 데이터를 검색, 삽입, 업데이트, 삭제하는데 사용됩니다. MySQL은 이러한 SQL 문을 이용하여 데이터를 쿼리하고, 데이터의 무결성을 유지하며, 데이터베이스를 관리합니다.
MySQL은 사용이 간편하며, 대용량 데이터베이스를 처리할 수 있는 고성능 기능을 제공합니다. 또한, 오픈 소스로서, 다양한 개발자들이 지속적으로 개발 및 유지보수하고 있어, 사용자들이 다양한 문제들을 해결할 수 있는 방법을 제공합니다.

MySQL은 PHP 스크립트 언어와 상호 연동이 잘 되면서 오픈소스로 개발된 무료 프로그램입니다. 그래서 홈페이지나 쇼핑몰(워드프레스, Cafe24, 그누보드, 제로보드)에 가장 일반적으로 사용하고 있습니다.

MySQL 설치

MAMP란 웹사이트를 개발할 때 쓰이는 기술 스택인 macOS, Apache, MySQL, PHP의 약어이자 솔루션 스택이다.
https://www.mamp.info/en/downloads/

MySQL 실행

먼저 cmd창을 열어서 cd c:\/MAMP/bin/mysql/bin를 입력하고 bin폴더에 접속한 후 mysql -uroot -proot를 입력하여 로그인을 합니다. 로그인이 성공하면 Welcome to the MySQL을 확인할 수 있습니다.

윈도우 : cd c:\/MAMP/bin/mysql/bin
로그인 : mysql -uroot -proot
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
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 /Applications/MAMP/Library/bin
로그인 : ./mysql -uroot -proot
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
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.

데이터베이스

데이터베이스 보기

show databases; 를 입력하면 데이터 베이스를 확인할 수 있습니다.
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.01 sec)

데이터베이스 만들기

create detabase 데이터베이스 이름;  create detabase sample01을 입력해 sample01을 추가해 줍니다.
mysql> create database sample01;
Query OK, 1 row affected (0.00 sec)

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sample01           |
| sys                |
+--------------------+
5 rows in set (0.00 sec)

데이터베이스 사용

use 데이터베이스 이름; ues sample01을 입력해 데이터 베이스를 변경해 줍니다.
mysql> use sample01;
Database changed

데이터베이스 삭제

drop database 데이터베이스 이름 drop database sample01을 입력하여 sample01을 삭제시켜 줍니다.
mysql> drop database sample01;
Query OK, 0 rows affected (0.01 sec)

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)

테이블

테이블 만들기

create table 테이블 이름;  create table member를 입력하여 새로운 테이블을 만들어 줍니다.
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,
    youAge int(5) 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)

테이블 보기

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    |                |
| youAge     | int(5)           | NO   |     | NULL    |                |
| regTime    | int(20)          | NO   |     | NULL    |                |
+------------+------------------+------+-----+---------+----------------+
7 rows in set (0.00 sec)

테이블 삭제

drop table 테이블 이름;  drop table member를 입력하여 이름이 member인 테이블을 삭제합니다.
mysql> drop table member;
Query OK, 0 rows affected (0.00 sec)

mysql> show tables;
Empty set (0.00 sec)

 

이외에도 MySQL에는 다양한 기능과 명령어가 있으며, 이를 학습하여 데이터베이스 관리 및 개발에 활용할 수 있습니다.

728x90