반응형
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는 username 및 password이며 localhost에서 호스팅됩니다.
SELECT COUNT(*) FROM information_schema.tables
이것이 도움이되기를 바라며 데이터베이스의 테이블 수만 반환합니다.
Use database;
SELECT COUNT(*) FROM sys.tables;
참고URL : https://stackoverflow.com/questions/5201012/query-to-count-the-number-of-tables-i-have-in-mysql
반응형
'IT story' 카테고리의 다른 글
| 글라이드를 사용하여 이미지를 비트 맵으로 다운로드하는 방법은 무엇입니까? (0) | 2020.07.18 |
|---|---|
| POSIX sh에 문자열에 다른 문자열이 포함되어 있는지 어떻게 알 수 있습니까? (0) | 2020.07.18 |
| git : 메시지를 입력하는 동안 중단 커밋 (0) | 2020.07.18 |
| HttpURLConnection과 함께 POST를 사용하여 파일 보내기 (0) | 2020.07.18 |
| 리스트 이해의 람다 함수 (0) | 2020.07.18 |