MySQL 뷰 목록 조회하기
MySQL에서 데이터베이스에 생성된 뷰(View)의 전체 목록을 확인하려면 information_schema.tables 테이블을 조회하면 됩니다. 특히 SELECT 명령어와 LIKE 연산자를 함께 사용하면 손쉽게 뷰만 골라낼 수 있습니다.
기본 문법
뷰 목록을 가져오는 기본적인 쿼리 문법은 다음과 같습니다.
mysql> SELECT TABLE_SCHEMA, TABLE_NAME -> FROM information_schema.tables -> WHERE TABLE_TYPE LIKE 'VIEW';
위 쿼리는 information_schema의 tables 테이블에서 TABLE_TYPE 값이 'VIEW'인 행만 필터링하여, 해당 뷰가 속한 스키마(TABLE_SCHEMA)와 뷰 이름(TABLE_NAME)을 반환합니다.
실행 결과 예시
아래는 실제 실행 결과로, 시스템 스키마인 sys에 포함된 다양한 뷰들이 출력된 모습입니다.
+--------------+-----------------------------------------------+ | TABLE_SCHEMA | TABLE_NAME | +--------------+-----------------------------------------------+ | sys | version | | sys | innodb_buffer_stats_by_schema | | sys | x$innodb_buffer_stats_by_schema | | sys | innodb_buffer_stats_by_table | | sys | x$innodb_buffer_stats_by_table | | sys | schema_object_overview | | sys | schema_auto_increment_columns | | sys | x$schema_flattened_keys | | sys | schema_redundant_indexes | | sys | ps_check_lost_instrumentation | | sys | latest_file_io | | sys | x$latest_file_io | | sys | io_by_thread_by_latency | | sys | x$io_by_thread_by_latency | | sys | io_global_by_file_by_bytes | | sys | x$io_global_by_file_by_bytes | | sys | io_global_by_file_by_latency | | sys | x$io_global_by_file_by_latency | | sys | io_global_by_wait_by_bytes | | sys | x$io_global_by_wait_by_bytes | | sys | io_global_by_wait_by_latency | | sys | x$io_global_by_wait_by_latency | | sys | innodb_lock_waits | | sys | x$innodb_lock_waits | | sys | memory_by_user_by_current_bytes | | sys | x$memory_by_user_by_current_bytes | | sys | memory_by_host_by_current_bytes | | sys | x$memory_by_host_by_current_bytes | | sys | memory_by_thread_by_current_bytes | | sys | x$memory_by_thread_by_current_bytes | | sys | memory_global_by_current_bytes | | sys | x$memory_global_by_current_bytes | | sys | memory_global_total | | sys | x$memory_global_total | | sys | schema_index_statistics | | sys | x$schema_index_statistics | | sys | x$ps_schema_table_statistics_io | | sys | schema_table_statistics | | sys | x$schema_table_statistics | | sys | schema_table_statistics_with_buffer | | sys | x$schema_table_statistics_with_buffer | | sys | schema_tables_with_full_table_scans | | sys | x$schema_tables_with_full_table_scans | | sys | schema_unused_indexes | | sys | schema_table_lock_waits | | sys | x$schema_table_lock_waits | | sys | statement_analysis | | sys | x$statement_analysis | | sys | statements_with_errors_or_warnings | | sys | x$statements_with_errors_or_warnings | | sys | statements_with_full_table_scans | | sys | x$statements_with_full_table_scans | | sys | x$ps_digest_avg_latency_distribution | | sys | x$ps_digest_95th_percentile_by_avg_us | | sys | statements_with_runtimes_in_95th_percentile | | sys | x$statements_with_runtimes_in_95th_percentile | | sys | statements_with_sorting | | sys | x$statements_with_sorting | | sys | statements_with_temp_tables | | sys | x$statements_with_temp_tables | | sys | user_summary_by_file_io_type | | sys | x$user_summary_by_file_io_type | | sys | user_summary_by_file_io | | sys | x$user_summary_by_file_io | | sys | user_summary_by_statement_type | | sys | x$user_summary_by_statement_type | | sys | user_summary_by_statement_latency | | sys | x$user_summary_by_statement_latency | | sys | user_summary_by_stages | | sys | x$user_summary_by_stages | | sys | user_summary | | sys | x$user_summary | | sys | host_summary_by_file_io_type | | sys | x$host_summary_by_file_io_type | | sys | host_summary_by_file_io | | sys | x$host_summary_by_file_io | | sys | host_summary_by_statement_type | | sys | x$host_summary_by_statement_type | | sys | host_summary_by_statement_latency | | sys | x$host_summary_by_statement_latency | | sys | host_summary_by_stages | | sys | x$host_summary_by_stages | | sys | host_summary | | sys | x$host_summary | | sys | wait_classes_global_by_avg_latency | | sys | x$wait_classes_global_by_avg_latency | | sys | wait_classes_global_by_latency | | sys | x$wait_classes_global_by_latency | | sys | waits_by_user_by_latency | | sys | x$waits_by_user_by_latency | | sys | waits_by_host_by_latency | | sys | x$waits_by_host_by_latency | | sys | waits_global_by_latency | | sys | x$waits_global_by_latency | | sys | metrics | | sys | processlist | | sys | x$processlist | | sys | session | | sys | x$session | | sys | session_ssl_status | +--------------+-----------------------------------------------+ 100 rows in set (0.01 sec)
실행 결과를 보면 총 100개의 뷰가 조회되었으며, 대부분 MySQL 5.7 이상에서 기본 제공되는 sys 스키마에 속해 있습니다. 이러한 시스템 뷰들은 서버 성능 분석, 메모리 사용량 모니터링, 잠금(Lock) 상태 확인 등 데이터베이스 관리에 유용하게 활용됩니다.
특정 스키마의 뷰만 조회하기
전체 뷰가 아닌 특정 데이터베이스(스키마)에 속한 뷰만 확인하고 싶다면 WHERE 절에 조건을 추가하면 됩니다.
mysql> SELECT TABLE_SCHEMA, TABLE_NAME -> FROM information_schema.tables -> WHERE TABLE_TYPE LIKE 'VIEW' -> AND TABLE_SCHEMA = 'your_database_name';
'your_database_name' 부분을 실제 사용 중인 데이터베이스 이름으로 바꿔주면 해당 스키마의 뷰 목록만 깔끔하게 확인할 수 있습니다.
SHOW FULL TABLES 활용하기
더 간단한 방법을 선호한다면 SHOW FULL TABLES 명령어도 좋은 선택입니다. 현재 선택된 데이터베이스 내에서 테이블과 뷰를 구분해서 보여줍니다.
mysql> SHOW FULL TABLES WHERE Table_type = 'VIEW';
이 명령어는 별도의 조건 작성 없이 직관적으로 사용할 수 있어, 간단히 뷰 목록을 확인할 때 자주 활용됩니다.