메뉴 건너뛰기

Korea Oracle User Group

DBMS

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

 

3.3 Creating and Using a Database

 

이후로 아래 내용에 대해서 살펴 볼 것이다.

 

  • Create a database
  • Create a table
  • Load data into the table
  • Retrieve data from the table in various ways
  • Use multiple tables

 

현재 서버에 사용 가능한 데이터베이스를 확인하려면 SHOW 문장을 아래와 같이 사용해 보자

 

mysql> SHOW DATABASES;
+--------------------+
| Database           |
+--------------------+
| dbperson           |
| information_schema |
| mpdbdiag           |
| mysql              |
| performance_schema |
| sakila             |
| sys                |
| world              |
+--------------------+
8 rows in set (0.01 sec)

 

위에 열겨된 데이터베이스 중 특정 데이터베이스를 사용하기 위해서는 아래와 같이 USE 명령어를 통해 사용할 데이터베이스를 지정해야 한다.

 

mysql> USE DBPERSON
Database changed
mysql>

 

생성된 데이터베이스에 접근 가능한 유저의 경우 데이터베이스내의 모든 것을 제거 가능하기 때문에 권한에 대한 관리를 해 주어야 한다.

 

아래는 유저를 생성하고 해당 유저에게 특정 데이터베이스만 사용 가능하게 권한을 부여하는 내용이다.

 

-- root 유저에서 db_mon 계정 생성

mysql> CREATE USER 'db_mon'@'localhost' IDENTIFIED BY 'db_mon';
Query OK, 0 rows affected (0.02 sec)

 

-- 생성된 계정으로 접속하여 사용 가능한 데이터베이스 확인

PS C:\Users\User> mysql -h localhost -u db_mon -p
Enter password: ******
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 17
Server version: 8.0.17 MySQL Community Server - GPL

Copyright (c) 2000, 2019, 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 |
+--------------------+
1 row in set (0.00 sec)

 

 

 

-- root 유저에서 db_mon 계정 생성
mysql> CREATE USER 'db_mon'@'localhost' IDENTIFIED BY 'db_mon';
Query OK, 0 rows affected (0.02 sec)

-- 생성된 계정으로 접속하여 사용 가능한 데이터베이스 확인
PS C:\Users\User> mysql -h localhost -u db_mon -p
Enter password: ******
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 17
Server version: 8.0.17 MySQL Community Server - GPL

Copyright (c) 2000, 2019, 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 |
+--------------------+
1 row in set (0.00 sec)

-- 현재 사용 가능한 데이터베이스가 보이지 않는다. 권한을 부여하지 않았기 때문이다. root 계정으로 접속해 dbperson 데이터베이스를 사용할 수 있도록 권한을 부여해 본다.
PS C:\Users\User> mysql -u root -p
Enter password: *******
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 18
Server version: 8.0.17 MySQL Community Server - GPL

Copyright (c) 2000, 2019, 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           |
+--------------------+
| dbperson           |
| information_schema |
| mpdbdiag           |
| mysql              |
| performance_schema |
| sakila             |
| sys                |
| world              |
+--------------------+
8 rows in set (0.00 sec)

mysql> GRANT ALL ON dbperson.* to 'db_mon'@'localhost';
Query OK, 0 rows affected (0.01 sec)

-- 이제 권한을 부여 받았으니 다시 db_mon 계정으로 접속하여 사용 가능한 데이터베이스를 확인하고 USE 명령어를 통해 변경해 보자
PS C:\Users\User> mysql -h localhost -u db_mon -p
Enter password: ******
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 19
Server version: 8.0.17 MySQL Community Server - GPL

Copyright (c) 2000, 2019, 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           |
+--------------------+
| dbperson           |
| information_schema |
+--------------------+
2 rows in set (0.00 sec)

mysql> USE dbperson
Database changed
mysql>

 

 

 

 

 

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