Skip to Content
Learning Linux Shell Scripting - Second Edition
book

Learning Linux Shell Scripting - Second Edition

by Ganesh Sanjiv Naik
May 2018
Beginner
332 pages
7h 28m
English
Packt Publishing
Content preview from Learning Linux Shell Scripting - Second Edition

Creating a user

Next, you will learn about creating a new user using the MySQL command inside shell script. The CREATE USER command creates a new user and we set a password for the newly created user. The command GRANT ALL ON provides privileges to make changes to database by newly created user.

In the next script, we will create a user and we will also grant all of the privileges on the database. Let's create the script mysql_04.sh to create a user:

#!/bin/bash 
mysql -u root -pTraining2@^ <<MY_QUERY 
CREATE USER 'user1'@'localhost' IDENTIFIED BY 'Test623@!@!'; 
GRANT ALL ON testdb.* TO 'user1'@'localhost'; 
select user from mysql.user; 
MY_QUERY 

Save the script and run it as follows:

                    $ chmod +x mysql_04.sh
          $ ./mysql_04.sh  

The output will ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Learning Linux Shell Scripting

Learning Linux Shell Scripting

Ganesh Sanjiv Naik
Linux Shell Scripting Cookbook - Third Edition

Linux Shell Scripting Cookbook - Third Edition

Clif Flynt, Sarath Lakshman, Shantanu Tushar

Publisher Resources

ISBN: 9781788993197Supplemental Content