DB/명령프롬프트 - mysql

[MySQL] Database 확인 show, use, select

congs 2023. 3. 26. 21:51
  • mysql> show databases; / /mysql의 데이터베이스를 보여주세요
  • mysql> use test; // Database의 test를 사용합니다
  • mysql> show tables; // test의 테이블을 보여주세요
  • mysql> select*from test1; // test1 table 전체출력
  • mysql> select*from test1 where address = "서울시"; // address가 서울시인 test1 table전체 출력
Microsoft Windows [Version 10.0.19045.2728]
(c) Microsoft Corporation. All rights reserved.

C:\Users\EZEN-217T>mysql -uroot -pezen //mysql에 연결합니다
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 28
Server version: 8.0.32 MySQL Community Server - GPL

Copyright (c) 2000, 2023, 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> show databases; //mysql의 데이터베이스를 보여주세요
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sakila             |
| sys                |
| test               |
| world              |
+--------------------+
7 rows in set (0.00 sec)

mysql> use test; //Database의 test를 사용합니다
Database changed //
mysql> show tables; //test의 테이블을 보여주세요
+----------------+
| Tables_in_test |
+----------------+
| test1          |
| test2          |
+----------------+
2 rows in set (0.00 sec)

mysql> select*from test1;
+----+--------+------+---------+
| id | name   | age  | address |
+----+--------+------+---------+
|  1 | 홍길동 |   25 | 서울시  |
|  2 | 홍길순 |   23 | 서울시  |
|  3 | 강길순 |   22 | 인천시  |
|  4 | 고길동 |   40 | 안양시  |
|  5 | 강감찬 |   45 | 안양시  |
+----+--------+------+---------+
5 rows in set (0.00 sec)

mysql> select*from test1 where address = "서울시";
+----+--------+------+---------+
| id | name   | age  | address |
+----+--------+------+---------+
|  1 | 홍길동 |   25 | 서울시  |
|  2 | 홍길순 |   23 | 서울시  |
+----+--------+------+---------+
2 rows in set (0.00 sec)