Get all tables from information_schema, MySQL

后端 未结 2 1579
孤独总比滥情好
孤独总比滥情好 2021-02-15 18:26

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:20

    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)
    

提交回复
热议问题