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

前端 未结 8 1950
天命终不由人
天命终不由人 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:34

    Please create the bash script like below and it will prompt you for details.

    LINUX ONLY - BASH SCRIPT - describe-all-tables.sh

    #!/bin/sh
    
    echo ""
    read -p 'MySQL db: ' DB
    echo ""
    read -p 'MySQL user: ' USER
    echo ""
    read -e -p 'MySQL host: ' -i "localhost" HOSTNAME
    echo ""
    read -s -p 'MySQL password: ' PASSWORD
    echo ""
    
    mysql -N -u${USER} ${DB} -p${PASSWORD} -h ${HOSTNAME} --execute="show tables" | while read table; do mysql -u${USER} -h ${HOSTNAME} ${DB} -p${PASSWORD} -v -t --execute="describe $table"; echo -e "\n"; done
    

    USAGE - /bin/sh describe-all-tables.sh

提交回复
热议问题