Get all tables from information_schema, MySQL

后端 未结 2 657
无人及你
无人及你 2021-02-15 18:50

I just dont understand one thing. When I type:

SELECT table_name FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = \'BASE TABLE\';

I get:



        
相关标签:
2条回答
  • 2021-02-15 19:00

    'information_schema' has ONLY SERVICE INFORMATION. It has info about table 'db' is exist, but it table IS NOT IN 'information_schema' DATABASE -- somewhere, but not in 'information_schema'.

    Info about database which has needed table saved in TABLE_SCHEMA field

    0 讨论(0)
  • 2021-02-15 19:25

    You select only table_name, but what about table_schema:

    MariaDB [(none)]> SELECT table_name, table_schema FROM INFORMATION_SCHEMA.TABLES WHERE 
    
        TABLE_TYPE = 'BASE TABLE';
        +----------------------------------------------+--------------------+
        | table_name                                   | table_schema       |
        +----------------------------------------------+--------------------+
        | columns_priv                                 | mysql              |
        | db                                           | mysql              |
        | event                                        | mysql              |
        | func                                         | mysql              |
        | general_log                                  | mysql              |
        | help_category                                | mysql              |
        | help_keyword                                 | mysql              |
        | help_relation                                | mysql              |
        | help_topic                                   | mysql              |
        | host                                         | mysql              |
        | ndb_binlog_index                             | mysql              |
        | plugin                                       | mysql              |
        | proc                                         | mysql              |
        | procs_priv                                   | mysql              |
        | proxies_priv                                 | mysql              |
        | servers                                      | mysql              |
        | slow_log                                     | mysql              |
        | tables_priv                                  | mysql              |
        | time_zone                                    | mysql              |
        | time_zone_leap_second                        | mysql              |
        | time_zone_name                               | mysql              |
        | time_zone_transition                         | mysql              |
        | time_zone_transition_type                    | mysql              |
        | user                                         | mysql              |
        | cond_instances                               | performance_schema |
        | events_waits_current                         | performance_schema |
        | events_waits_history                         | performance_schema |
        | events_waits_history_long                    | performance_schema |
        | events_waits_summary_by_instance             | performance_schema |
        | events_waits_summary_by_thread_by_event_name | performance_schema |
        | events_waits_summary_global_by_event_name    | performance_schema |
        | file_instances                               | performance_schema |
        | file_summary_by_event_name                   | performance_schema |
        | file_summary_by_instance                     | performance_schema |
        | mutex_instances                              | performance_schema |
        | performance_timers                           | performance_schema |
        | rwlock_instances                             | performance_schema |
        | setup_consumers                              | performance_schema |
        | setup_instruments                            | performance_schema |
        | setup_timers                                 | performance_schema |
        | threads                                      | performance_schema |
        +----------------------------------------------+--------------------+
    

    And you get:

    MariaDB [(none)]> select * from mysql.db;
    Empty set (0.00 sec)
    
    0 讨论(0)
提交回复
热议问题