我正在增加我拥有的表的数量,我有时好奇只是做一个快速的命令行查询来计算我的数据库中的表数。那可能吗?如果是,查询是什么?
答案 0 :(得分:262)
SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = 'dbName';
这是我的:
USE databasename;
SHOW TABLES;
SELECT FOUND_ROWS();
答案 1 :(得分:24)
如果您想要计算所有数据库和摘要,请尝试以下方法:
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)
试一试!!!
答案 2 :(得分:8)
SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = 'dbo' and TABLE_TYPE='BASE TABLE'
答案 3 :(得分:3)
这将为您提供mysql中所有数据库的名称和表计数
SELECT TABLE_SCHEMA,COUNT(*) FROM information_schema.tables group by TABLE_SCHEMA;
答案 4 :(得分:2)
要计算表数,请执行以下操作:
USE your_db_name; -- set database
SHOW TABLES; -- tables lists
SELECT FOUND_ROWS(); -- number of tables
有时容易做的事情会起作用。
答案 5 :(得分:2)
SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = 'database_name';
答案 6 :(得分:1)
可能有多种方法来计算数据库的表。我最喜欢的是:
SELECT
COUNT(*)
FROM
`information_schema`.`tables`
WHERE
`table_schema` = 'my_database_name'
;
答案 7 :(得分:1)
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';
答案 8 :(得分:1)
来自命令行:
mysql -uroot -proot -e "select count(*) from
information_schema.tables where table_schema = 'database_name';"
在上面的示例中,root是用户名和密码,托管在localhost上。
答案 9 :(得分:0)
SELECT COUNT(*) FROM information_schema.tables
答案 10 :(得分:0)
答案 11 :(得分:-1)
希望这会有所帮助,并且只返回数据库中的表数
Use database;
SELECT COUNT(*) FROM sys.tables;