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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.