MySQL数据库表格列表和记录数量列表
事前的知識
MySQL用語集(MySQL Glossary)的中譯版本。
In MySQL, physically, a schema is synonymous with a database.
MySQLでは、物理的に、スキーマ はデータベースと同義です。
由于数据库的不同,模式和数据库的含义可能会有所不同,因此需要注意。
Oracle实例=数据库 > 模式=用户 > 表
MySQL实例 > 数据库 = 模式 > 表
登录MySQL
# mysql -u ユーザ -pパスワード
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 15
Server version: 8.0.20 MySQL Community Server - GPL
Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
表格列表
mysql> SHOW TABLES FROM db_name;
+---------------------------------+
| Tables_in_banana |
+---------------------------------+
| auth_group |
| auth_group_permissions |
| auth_permission |
| auth_user |
| auth_user_groups |
| auth_user_user_permissions |
| django_admin_log |
| django_content_type |
| django_migrations |
| django_session |
(省略)
+---------------------------------+
46 rows in set (0.01 sec)
mysql> SELECT TABLE_NAME FROM information_schema.TABLES;
+---------------------------------------+
| TABLE_NAME |
+---------------------------------------+
| auth_group |
| auth_group_permissions |
| auth_permission |
| auth_user |
| auth_user_groups |
| auth_user_user_permissions |
| django_admin_log |
| django_content_type |
| django_migrations |
| django_session |
(省略)
| ADMINISTRABLE_ROLE_AUTHORIZATIONS |
| APPLICABLE_ROLES |
| CHARACTER_SETS |
| CHECK_CONSTRAINTS |
| COLLATIONS |
| COLLATION_CHARACTER_SET_APPLICABILITY |
| COLUMNS |
| COLUMN_PRIVILEGES |
| COLUMN_STATISTICS |
| ENABLED_ROLES |
| ENGINES |
| EVENTS |
| FILES |
| INNODB_BUFFER_PAGE |
| INNODB_BUFFER_PAGE_LRU |
| INNODB_BUFFER_POOL_STATS |
(省略)
| KEYWORDS |
| KEY_COLUMN_USAGE |
| OPTIMIZER_TRACE |
| PARAMETERS |
| PARTITIONS |
| PLUGINS |
| PROCESSLIST |
| PROFILING |
| REFERENTIAL_CONSTRAINTS |
| RESOURCE_GROUPS |
| ROLE_COLUMN_GRANTS |
| ROLE_ROUTINE_GRANTS |
| ROLE_TABLE_GRANTS |
| ROUTINES |
| SCHEMATA |
| SCHEMA_PRIVILEGES |
| STATISTICS |
| ST_GEOMETRY_COLUMNS |
| ST_SPATIAL_REFERENCE_SYSTEMS |
| ST_UNITS_OF_MEASURE |
| TABLES |
| TABLESPACES |
| TABLE_CONSTRAINTS |
| TABLE_PRIVILEGES |
| TRIGGERS |
| USER_PRIVILEGES |
| VIEWS |
| VIEW_ROUTINE_USAGE |
| VIEW_TABLE_USAGE |
+---------------------------------------+
119 rows in set (0.01 sec)
mysql> SELECT TABLE_NAME FROM information_schema.TABLES WHERE TABLE_SCHEMA = 'db_name';
+---------------------------------+
| TABLE_NAME |
+---------------------------------+
| auth_group |
| auth_group_permissions |
| auth_permission |
| auth_user |
| auth_user_groups |
| auth_user_user_permissions |
| django_admin_log |
| django_content_type |
| django_migrations |
| django_session |
(省略)
+---------------------------------+
46 rows in set (0.00 sec)
记录数量列表
mysql> SELECT TABLE_NAME, TABLE_ROWS FROM information_schema.TABLES WHERE TABLE_SCHEMA = 'db_name';
+---------------------------------+------------+
| TABLE_NAME | TABLE_ROWS |
+---------------------------------+------------+
| auth_group | 0 |
| auth_group_permissions | 0 |
| auth_permission | 168 |
| auth_user | 2 |
| auth_user_groups | 0 |
| auth_user_user_permissions | 164 |
| django_admin_log | 10 |
| django_content_type | 42 |
| django_migrations | 20 |
| django_session | 19 |
(省略)
+---------------------------------+------------+
46 rows in set (0.18 sec)