Select data from “show tables” MySQL query

后端 未结 13 1668
难免孤独
难免孤独 2020-12-01 04:15

Is it possible to select from show tables in MySQL?

SELECT * FROM (SHOW TABLES) AS `my_tables`

Something along these lines, th

相关标签:
13条回答
  • 2020-12-01 04:33

    in MySql 5.1 you can try

    show tables like 'user%';
    

    output:

    mysql> show tables like 'user%';
    
    +----------------------------+
    
    | Tables_in_test (user%) |
    
    +----------------------------+
    
    | user                       |
    
    | user_password              |
    
    +----------------------------+
    
    2 rows in set (0.00 sec)
    
    0 讨论(0)
  • 2020-12-01 04:34
    SELECT * FROM INFORMATION_SCHEMA.TABLES
    

    That should be a good start. For more, check INFORMATION_SCHEMA Tables.

    0 讨论(0)
  • 2020-12-01 04:38
    SELECT column_comment FROM information_schema.columns WHERE table_name = 'myTable' AND column_name = 'myColumnName'
    

    This will return the comment on: myTable.myColumnName

    0 讨论(0)
  • 2020-12-01 04:41

    Not that I know of, unless you select from INFORMATION_SCHEMA, as others have mentioned.

    However, the SHOW command is pretty flexible, E.g.:

    SHOW tables like '%s%'
    
    0 讨论(0)
  • 2020-12-01 04:41

    Yes, SELECT from table_schema could be very usefull for system administration. If you have lot of servers, databases, tables... sometimes you need to DROP or UPDATE bunch of elements. For example to create query for DROP all tables with prefix name "wp_old_...":

    SELECT concat('DROP TABLE ', table_name, ';') FROM INFORMATION_SCHEMA.TABLES
    WHERE table_schema = '*name_of_your_database*'
    AND table_name LIKE 'wp_old_%';
    
    0 讨论(0)
  • 2020-12-01 04:44

    To count:

    SELECT COUNT(*) as total FROM (SELECT TABLE_NAME as tab, TABLES.* FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='database_name' GROUP BY tab) tables;
    

    To list:

    SELECT TABLE_NAME as table, TABLES.* FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='database_name' GROUP BY table;
    
    0 讨论(0)
提交回复
热议问题