반응형
MySQL에 있는 테이블 수를 세는 쿼리
테이블 수가 증가하고 있는데 데이터베이스 내의 테이블 수를 세는 간단한 명령줄 쿼리만 해도 궁금할 때가 있습니다.그게 가능한가요?그렇다면 어떤 질문입니까?
SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = 'dbName';
이건 내 거야
USE databasename;
SHOW TABLES;
SELECT FOUND_ROWS();
모든 데이터베이스와 요약을 카운트하고 싶은 경우 다음을 시도해 보십시오.
SELECT IFNULL(table_schema,'Total') "Database",TableCount
FROM (SELECT COUNT(1) TableCount,table_schema
FROM information_schema.tables
WHERE table_schema NOT IN ('information_schema','mysql')
GROUP BY table_schema WITH ROLLUP) A;
다음은 샘플 실행입니다.
mysql> SELECT IFNULL(table_schema,'Total') "Database",TableCount
-> FROM (SELECT COUNT(1) TableCount,table_schema
-> FROM information_schema.tables
-> WHERE table_schema NOT IN ('information_schema','mysql')
-> GROUP BY table_schema WITH ROLLUP) A;
+--------------------+------------+
| Database | TableCount |
+--------------------+------------+
| performance_schema | 17 |
| Total | 17 |
+--------------------+------------+
2 rows in set (0.29 sec)
시험해 보세요!!!
SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = 'dbo' and TABLE_TYPE='BASE TABLE'
그러면 mysql에 있는 모든 데이터베이스의 이름과 테이블 수가 표시됩니다.
SELECT TABLE_SCHEMA,COUNT(*) FROM information_schema.tables group by TABLE_SCHEMA;
테이블 수를 카운트하려면 다음 절차를 수행합니다.
USE your_db_name; -- set database
SHOW TABLES; -- tables lists
SELECT FOUND_ROWS(); -- number of tables
때로는 쉬운 것이 그 일을 해낼 것이다.
SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = 'database_name';
데이터베이스의 테이블을 카운트하는 방법은 여러 가지가 있습니다.내가 가장 좋아하는 것은 이것이다.
SELECT
COUNT(*)
FROM
`information_schema`.`tables`
WHERE
`table_schema` = 'my_database_name'
;
select name, count(*) from DBS, TBLS
where DBS.DB_ID = TBLS.DB_ID
group by NAME into outfile '/tmp/QueryOut1.csv'
fields terminated by ',' lines terminated by '\n';
명령줄에서:
mysql -uroot -proot -e "select count(*) from
information_schema.tables where table_schema = 'database_name';"
위의 예에서 root은 localhost에서 호스트되는 사용자 이름과 비밀번호입니다.
SELECT COUNT(*) FROM information_schema.tables
mysql> 테이블 표시
테이블 이름이 표시되고 테이블 수가 표시됩니다.
이것이 도움이 되기를 바라며 데이터베이스의 테이블 수만 반환합니다.
Use database;
SELECT COUNT(*) FROM sys.tables;
언급URL : https://stackoverflow.com/questions/5201012/query-to-count-the-number-of-tables-i-have-in-mysql
반응형
'source' 카테고리의 다른 글
| MySQL join with where 절 (0) | 2022.11.11 |
|---|---|
| Array IE8에서 Index Of가 작동하지 않는 이유는 무엇입니까? (0) | 2022.11.11 |
| SQL 피벗 및 문자열로 저장된 날짜 간의 차이 계산 - MySQL (0) | 2022.11.11 |
| 단일 null 인수를 사용하여 Java varargs 메서드를 호출하시겠습니까? (0) | 2022.11.11 |
| MySQL my.cnf 파일 - 이전 그룹이 없는 옵션을 찾았습니다. (0) | 2022.11.11 |