Creating a table in MySQL

We have successfully created a database named testdb and a user named user1, and have also granted all of the privileges on the testdb database.

Now we will create a table. Create the script mysql_05.sh to list the table:

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

Now save the program and run it as follows:

          $ chmod +x mysql_05.sh
          $ ./mysql_05.sh
  

The preceding command will not show presence of any table, as we only just have created our database.

Now, we are going to create a table named Authors. Create the script mysql_06.sh to create a table named Authors:

#!/bin/bash mysql -u user1 -pTest623@! <<MY_QUERY use testdb; CREATE TABLE Authors(Id INT PRIMARY KEY AUTO_INCREMENT, ...

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.