How can I describe all tables in the database through one statement?

前端 未结 8 1962
天命终不由人
天命终不由人 2021-01-31 08:01

Is there any statement that can describe all tables in a database?

Something like this:

describe * from myDB;
8条回答
  •  臣服心动
    2021-01-31 08:38

    I am using linux way. First create a ~/.my.cnf to store the username and password for mysql. Next use the snippet below and run it in the linux terminal.

    Generate the tables list and filter the header and awk to generate the column. Then, use the same method to DESC table_name.

    for i in $(mysql MYDBNAME -e 'SHOW TABLES' | grep -v "Tables_in" | awk '{print $1}'); do echo "TABLE: $i"; mysql MYDBNAME -e "DESC $i"; done
    

    Hope this helps.

提交回复
热议问题