mysql テーブル一覧 と レコード件数一覧

# 事前知識

[MySQL Glossary(MySQL用語集)](https://dev.mysql.com/doc/refman/8.0/en/glossary.html#glos_schema)

```:MySQL用語集より引用
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)
```