Describing a table

If we need to know more about the overall information or query the execution plan of an entire table, we need to use the DESCRIBE command.

We will create the script mysql_12.sh to obtain the table structure:

#!/bin/bash 
mysql -u user1 -pTest623@!  <<MY_QUERY 
use testdb; 
desc Authors; 
MY_QUERY 

Save the script and run it as follows:

          $ chmod +x mysql_12.sh
          $ ./mysql_12.sh
  

The output will be:

    Field Type  Null  Key   Default           Extra
    Id    int(11)     NO    PRI   NULL  auto_increment
    Name  varchar(25) YES   NULL  
    ADDRESS varchar(25)     YES   NULL
  

Get Learning Linux Shell Scripting - Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.