|
Home > Archive > MySQL Server Forum > June 2005 > copy user privileges to a newly created user.
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
copy user privileges to a newly created user.
|
|
| usaims 2005-06-27, 9:23 am |
| Hello:
I have just created a user with specific permissions to certain tables
in different databases. Now I have to create serveral more users with
the same permission. Is there a command in MySQL that allows me to
create the new user by copying the privileges from a template user?
MySQL 4.0.16
usaims
| |
| Thomas Bartkus 2005-06-27, 11:23 am |
| "usaims" <usaims@yahoo.com> wrote in message
news:1119880662.098488.303680@g47g2000cwa.googlegroups.com...
> Hello:
>
> I have just created a user with specific permissions to certain tables
> in different databases. Now I have to create serveral more users with
> the same permission. Is there a command in MySQL that allows me to
> create the new user by copying the privileges from a template user?
I believe you will want to script it using your favorite language - be it a
DOS batch file, VB script, VBA, BASH, Python, Perl. You want to pass 1 or
more GRANT statements to MySQL using a usr name and host as the input.
Here is a minimalist Linux/BASH example. Sorry - I don't remember enough DOS
batch file language except to say it would look exceedingly similar
------------------------------------------------------------------------
#! /bin/bash
# Did we specify the user name@host on the command line?
if [ $# -ne 1 ]
then echo 'Aborted! - Need to specify "usr@host" on the command line'
exit
fi
# The $1 parameter holds our usr@host variable
mysql -uYourUsr -pYourPwd <<USER_PERMIT
GRANT SELECT ON SomeDB.SomeTable TO "$1"
GRANT SELECT ON SomeOtherDB.SomeOtherTable TO "$1"
USER_PERMIT
| |
| Thomas Bartkus 2005-06-27, 11:23 am |
| "usaims" <usaims@yahoo.com> wrote in message
news:1119880662.098488.303680@g47g2000cwa.googlegroups.com...
> Hello:
>
> I have just created a user with specific permissions to certain tables
> in different databases. Now I have to create serveral more users with
> the same permission. Is there a command in MySQL that allows me to
> create the new user by copying the privileges from a template user?
I believe you will want to script it using your favorite language - be it a
DOS batch file, VB script, VBA, BASH, Python, Perl. You want to pass 1 or
more GRANT statements to MySQL using a usr name and host as the input.
Here is a minimalist Linux/BASH example. Sorry - I don't remember enough DOS
batch file language except to say it would look exceedingly similar
------------------------------------------------------------------------
#! /bin/bash
# Did we specify the user name@host on the command line?
if [ $# -ne 1 ]
then echo 'Aborted! - Need to specify "usr@host" on the command line'
exit
fi
# The $1 parameter holds our usr@host variable
mysql -uYourUsr -pYourPwd <<USER_PERMIT
GRANT SELECT ON SomeDB.SomeTable TO "$1"
GRANT SELECT ON SomeOtherDB.SomeOtherTable TO "$1"
USER_PERMIT
|
|
|
|
|