IT story

MySQL에있는 테이블 수를 계산하는 쿼리

hot-time 2020. 7. 18. 09:58
반응형

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

반응형