Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
adding mysql users programatically
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Networking & Security
View previous topic :: View next topic  
Author Message
cybert
n00b
n00b


Joined: 22 Mar 2003
Posts: 7

PostPosted: Thu Apr 03, 2003 2:31 pm    Post subject: adding mysql users programatically Reply with quote

This is probably a bit of a noob question but I am having a problem with mysql and adding users.

I am using the superadduser command to add new users and want to expand this tool to do the following...

1. create a database in mysql that is the same as the username
2. add the user to mysql with complete access to only his/her database
using the same password that was enetered

I am unsure of the grant statements to make this happen.

Any help would be appreciated.
_________________
CyberT
cybert_guess_what@to_do_cybert.org
Back to top
View user's profile Send private message
caffiend
n00b
n00b


Joined: 26 Mar 2003
Posts: 48
Location: Oakland, CA

PostPosted: Sat Apr 05, 2003 3:17 pm    Post subject: Reply with quote

well you'll need to write a script to handle all that. Python, perl, bash, or whatever.

and from the MySQL DOCS *cough cough* we have...

Code:
GRANT priv_type [(column_list)] [, priv_type [(column_list)] ...]
    ON {tbl_name | * | *.* | db_name.*}
    TO user_name [IDENTIFIED BY 'password']
        [, user_name [IDENTIFIED BY 'password'] ...]
    [WITH GRANT OPTION]


so you'll want something like
Code:
GRANT ALTER, INDEX, SELECT, CREATE, INSERT, DELETE, UPDATE ON usertable.* TO user@localhost IDENTIFIED BY 'password'
Back to top
View user's profile Send private message
Woland
Apprentice
Apprentice


Joined: 02 Aug 2002
Posts: 248
Location: Russian Jack, Alaska

PostPosted: Sun Apr 06, 2003 8:26 pm    Post subject: Reply with quote

caffiend wrote:
well you'll need to write a script to handle all that. Python, perl, bash, or whatever.

and from the MySQL DOCS *cough cough* we have...

Code:
GRANT priv_type [(column_list)] [, priv_type [(column_list)] ...]
    ON {tbl_name | * | *.* | db_name.*}
    TO user_name [IDENTIFIED BY 'password']
        [, user_name [IDENTIFIED BY 'password'] ...]
    [WITH GRANT OPTION]


so you'll want something like
Code:
GRANT ALTER, INDEX, SELECT, CREATE, INSERT, DELETE, UPDATE ON usertable.* TO user@localhost IDENTIFIED BY 'password'


Well, if I could undestand all that, I would not be searching through the fora, would I? :wink:

Has anyone such a script---even looking through it would hopefully despel some of the deep ignorance I have of this subject. I can't even figure out how to change the mysql root password trying to follow the instructions at the end of the ebuild.
Back to top
View user's profile Send private message
de4d
Apprentice
Apprentice


Joined: 12 Sep 2002
Posts: 181
Location: fr. i. br. (ger)

PostPosted: Mon Apr 07, 2003 10:03 am    Post subject: Reply with quote

something like this may work / seem easier 2 u
Code:

#!/bin/bash
#
#by dmk
if [ $# -eq 2 ]; then
DBNAME=$1
PASS=$2
else
echo "User/Databasename:"
read DBNAME
echo "Passwort:"
read PASS
fi

mysql -u root -p$ROOT_PASS -e "create database $DBNAME;"
mysql -u root -p$ROOT_PASS -e "use mysql; insert into user values ('%','$DBNAME',password('$PASS'),1,1,1,1,1,1,1,1,1,1,1,1,1,1);"
mysql -u root -p$ROOT_PASS -e "use mysql; insert into db values('%','$DBNAME','$DBNAME',2,2,2,2,2,2,1,2,2,2);"
mysql -u root -p$ROOT_PASS -e "flush privileges;"
echo "DB '$DBNAME' created. passwd: '$PASS'"

_________________
void main(){fork();main();}
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Networking & Security All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum