메뉴 건너뛰기

Korea Oracle User Group

DBMS

MySQL 8.0 Reference Manual - Tutorial - Creating and Using a Database2

 

3.3.1 Creating and Selecting a Database

 

데이터베이스 생성(현재 생성된 데이터베이스 확인)

 

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sakila             |
| sys                |
| world              |
+--------------------+
6 rows in set (0.01 sec)

mysql> CREATE DATABASE menagerie;
Query OK, 1 row affected (0.04 sec)

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| menagerie          |
| mysql              |
| performance_schema |
| sakila             |
| sys                |
| world              |
+--------------------+
7 rows in set (0.00 sec)

mysql>

 

Unix 시스템에서는 데이터베이스의 이름 생성시 대소문자 구분을 하기 때문에 주의해야 한다. 이는 테이블명도 같다.

 

이제 생성된 데이터베이스를 사용해 보도록 하자
 

mysql> use menagerie
Database changed
mysql> show tables;
Empty set (0.02 sec)

mysql>

 

위와 같이 특정 데이터베이스를 사용하고자 한다면 반드시 명시적으로 USE 명령어를 사용해 데이터베이스를 사용한다는 지정을 해야한다.

다른 방법으로 접속시 사용할 데이터베이스를 지정할 수도 있다.

 

PS C:\Users\ecros> mysql -u root -p menagerie
Enter password: *******
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 27
Server version: 8.0.19 MySQL Community Server - GPL

Copyright (c) 2000, 2020, 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> select database();
+-------------+
| database () |
+-------------+
| menagerie   |
+-------------+
1 row in set (0.00 sec)

mysql>

 

3.3.2 Creating a Table

 

데이터베이스에 있는 테이블 리스트는 아래 명령어를 통해 확인할 수 있다.

 

mysql> show tables;
Empty set (0.00 sec)

mysql>

 

이제 pet 테이블을 생성해 보도록 하자

 

mysql> CREATE TABLE pet(
    -> name VARCHAR(20),
    -> owner VARCHAR(20),
    -> species VARCHAR(20),
    -> sex CHAR(1),
    -> birth DATE,
    -> death DATE);
Query OK, 0 rows affected (0.11 sec)

mysql>

 

이제 생성된 테이블 리스트를 다시 확인해 보자

 

mysql> show tables;
+---------------------+
| Tables_in_menagerie |
+---------------------+
| pet                 |
+---------------------+
1 row in set (0.01 sec)

mysql>

 

테이블이 우리가 지정한대로 만들어졌는지 확인해 보자.

 

mysql> describe pet;
+---------+-------------+------+-----+---------+-------+
| Field   | Type        | Null | Key | Default | Extra |
+---------+-------------+------+-----+---------+-------+
| name    | varchar(20) | YES  |     | NULL    |       |
| owner   | varchar(20) | YES  |     | NULL    |       |
| species | varchar(20) | YES  |     | NULL    |       |
| sex     | char(1)     | YES  |     | NULL    |       |
| birth   | date        | YES  |     | NULL    |       |
| death   | date        | YES  |     | NULL    |       |
+---------+-------------+------+-----+---------+-------+
6 rows in set (0.01 sec)

mysql>

 

 

 

번호 제목 글쓴이 날짜 조회 수
19 PostgreSQL 16 설치하기(Installation) [1] 명품관 2024.01.24 411
18 Top-Rated PostgreSQL GUI Clients for Windows 명품관 2023.05.10 91
17 기동시 "Job for mysqld.service failed because the control process exited with error code." 에러로 기동 실패 명품관 2020.09.03 7919
16 MySQL 8.0 Reference Manual - MySQL Server Administration2 - Server Configuration Validation 명품관 2020.04.17 417
15 MySQL 8.0 Reference Manual - MySQL Server Administration1 - Configuring the Server 명품관 2020.03.05 9596
14 MySQL 8.0 Reference Manual - Tutorial - Creating and Using a Database4 명품관 2020.03.03 252
13 MySQL 8.0 Reference Manual - Tutorial - Creating and Using a Database3 명품관 2020.03.02 416
12 Windows 버전 MySQL의 my.ini 파일 찾기 file 명품관 2020.03.01 13296
» MySQL 8.0 Reference Manual - Tutorial - Creating and Using a Database2 명품관 2020.02.29 233
10 MySQL 8.0 Reference Manual - Tutorial - Creating and Using a Database1 명품관 2020.02.28 188
9 MySQL 8.0 Reference Manual - Tutorial - Entering Queries 명품관 2020.02.28 199
8 MySQL 8.0 Reference Manual - Tutorial - Connecting to and Disconnecting from the Server 명품관 2020.02.27 191
7 MySQL Admin - 01 명품관 2019.10.08 702
6 How to Install MariaDB 10 on RHEL 8 [2] 명품관 2019.01.31 252
5 MySQL 설치 후 외부 접속 허용하기 명품관 2016.09.09 2842
4 CentOS 6.7 에서 MySQL 5.7 설치 명품관 2016.09.09 13790
3 티베로 trace log 중 ERROR_PSM_COMPILE_FAILED 에러란 명품관 2016.09.06 11429
2 DP, DPL, DPI에 관한trace log 내용 분석 명품관 2016.09.06 1036
1 티베로 에러 내용 확인 방법 명품관 2016.08.26 10740
위로