LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 06-19-2007, 10:17 AM   #1
tanveer
Member
 
Registered: Feb 2004
Location: e@rth
Distribution: RHEL-3/4/5,Gloria,opensolaris
Posts: 525

Rep: Reputation: 39
mysql user creation script


Hi all,

How to run a script with all the commands of a user creation in mysql server 4.1.7 ?

Like I have to create a users in my PC and I want creat a script for that. The commands i use to creat a user is as follows:

Code:
GRANT SELECT(name,fname) on 'test`.`sample` to 'bob'@'localhost';
flush privileges;
UPDATE mysql.user set Password=PASSWORD('dummy') where user='bob' and Host='localhost';
flush privileges;
Now how to make a script so that whenever I run the script it will create the user using these 4 commands.

Thanks in advance.
 
Old 06-19-2007, 11:02 PM   #2
tanveer
Member
 
Registered: Feb 2004
Location: e@rth
Distribution: RHEL-3/4/5,Gloria,opensolaris
Posts: 525

Original Poster
Rep: Reputation: 39
Done. Thanks
 
Old 06-20-2007, 01:21 AM   #3
p_s_shah
Member
 
Registered: Mar 2005
Location: India
Distribution: RHEL 3/4, Solaris 8/9/10, Fedora 4/8, Redhat Linux 9
Posts: 237
Blog Entries: 1

Rep: Reputation: 34
Update us how did you achieve it.

IF i suppose to do :
Code:
[root@example root] cat dbuser_create.sh
# Information for connecting to mysql for running GRANT queries.
DBHOST=localhost
DBUSER=root
DBPWD=abc123
CMDFILE=usercreate.sql

# Gathering info for setting up GRANT queries.
echo "Enter Username"
read USERNAME
echo "Enter Password"
read USERPWD
echo "Enter DB"
read USERDB
echo "Enter Table"
read USERTBL

# Delete old file
rm -f $CMDFILE

# Creating File which contains SQL query
echo -e "GRANT SELECT(name,fname) on $USERDB.$USERTBL to $USERNAME@'localhost';\nflush privileges;\nUPDATE mysql.user set Password=PASSWORD($USERPWD) where user=$USERNAME and Host='localhost';\nflush privileges;" >> $CMDFILE

# Running query through mysql.
mysql -u $DBUSER -p`$DBPWD' $DBHOST < $CMDFILE
Add checking for USERNAME,USERPWD etc.

Last edited by p_s_shah; 06-20-2007 at 01:25 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
MySQL: Grant user database creation rights Swakoo Linux - General 4 09-13-2006 06:34 AM
Allowing the creation of MYSQL databases by a user rustyz82 Linux - Software 5 06-26-2006 01:11 AM
script creation woes mrgreaper Linux - Newbie 10 06-20-2006 07:41 AM
Mysql table creation problems!! linux_child001 Linux - Newbie 10 06-28-2004 01:10 PM
mysql database creation zuessh Linux - Software 17 05-14-2003 01:13 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 10:23 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration