Working with a MySQL Database
In this section, you will learn about automating MySQL database administration. Let's start with very basic activities, as discussed in the following topics.
Checking the version of MySQL database
We will initially start by checking which version of MySQL is installed. With this script, we will ensure that MySQL is properly installed and we are able to communicate with it with root privileges. This script will report us the database version of MySQL. It executes a SELECT VERSION()
query to get the value of the database version. Let's create the script mysql_01.sh
:
#!/bin/bash mysql -u root -pTraining2@^ <<MY_QUERY SELECT VERSION(); MY_QUERY
Save the program and execute it as follows:
$ chmod +x mysql_01.sh$ ./mysql_01.sh
The output will be:
VERSION()5.7.22
Creating a database
In this section, you will learn about a creating new database in MySQL. We are going to use this database throughout this chapter. Create the script mysql_02.sh
to create the database...