How to get all columns' names for all the tables in MySQL?

前端 未结 10 2238
你的背包
你的背包 2020-11-28 01:13

Is there a fast way of getting all column names from all tables in MySQL, without having to list all the tables?

相关标签:
10条回答
  • 2020-11-28 01:55

    I wrote this silly thing a long time ago and still actually use it now and then:

    https://gist.github.com/kphretiq/e2f924416a326895233d

    Basically, it does a "SHOW TABLES", then a "DESCRIBE " on each table, then spits it out as markdown.

    Just edit below the "if name" and go. You'll need to have pymysql installed.

    0 讨论(0)
  • 2020-11-28 01:56

    it is better that you use the following query to get all column names easily

    Show columns from tablename

    0 讨论(0)
  • 2020-11-28 01:57
    select * from information_schema.columns
    where table_schema = 'your_db'
    order by table_name,ordinal_position
    
    0 讨论(0)
  • 2020-11-28 02:00

    To list all the fields from a table in MySQL:

    select * 
      from information_schema.columns 
     where table_schema = 'your_DB_name' 
       and table_name = 'Your_tablename'
    
    0 讨论(0)
提交回复
热议问题