administering multiple databases on one server

Posted on 2005-04-19
Last Modified: 2008-03-06
I somehow got to be 'in charge' of a mysql database server that is to be used for many groups for different uses.

My intent is to create a database for each group and give one member of that group full permissions to that database only, but no power to mess up any other database.

So I run (for example):

> create database ktest4;
> grant all on ktest4.* to 'abc123'@'%' identified by 'abc123' with grant option;

This seems to work and user 'abc123' can login to the database ktest4.

However, now when the user 'abc123' wants to change their password, I tell them to type:

>mysql> SET PASSWORD FOR 'abc123'@'%' = PASSWORD('newpassword');

but they get:

>ERROR 1044: Access denied for user: 'abc123@%' to database 'mysql'

Strangely, if they type just 'abc123' instead of 'abc123'@'%' - that works, even tho my documentation says it's the same thing.

Also, when they want to create a new user for that database with limited privileges, I tell them to type:

mysql> grant SELECT, INSERT on ktest4.* to 'user_ktest4'@'%' identified by 'user_ktest4';

and again, they get:

ERROR 1044: Access denied for user: 'abc123@%' to database 'mysql'

Please explain this to me.  My primary documentation (MySQL by Paul DuBois) doesn't mention changes to the 'mysql' database...

Question by:red5
    LVL 14

    Expert Comment

    You should try: SET PASSWORD = PASSWORD('some password')
    To set the password for the current user.

    You need to give the user abc123 grant options, so they can create other users with equal or lower permissions using WITH GRANT OPTION when you create the user:

    Author Comment

    The alternate syntax for SET PASSWORD works.

    However, if you look at my original post, you can see that I *did* use 'with grant option', yet the grant command still fails.

    Is it possible that 'abc123' cannot 'create' user 'user_ktest4', but only modify it?

    I have given the exact commands; could you run them yourself and see if your 'abc123' account is allowed to create 'user_ktest4' ?
    LVL 14

    Expert Comment

    Sorry, I must have missed that line.

    On the same manual page, have you tried creating abc123 with 'CREATE USER' privileges. Or modifying the user to add them?

    Author Comment

    'CREATE USER' is only in version 5+.  Unfortunately, I'm stuck with version 4.0.18.

    I found that if I add 'INSERT' privilege to abc123 in the mysql database, then added a no-password account works:

    mysql> grant INSERT on ktest4.* to 'u4'@'%';                    
    Query OK, 0 rows affected (0.05 sec)

    but *WITH* a password fails:

    mysql> grant INSERT on ktest4.* to 'uu4'@'%' identified by 'uu4';
    ERROR 1044: Access denied for user: 'abc123@%' to database 'mysql'

    My theory at the moment is that the failing command does an insert followed by an update to add the password.  So this may require 'UPDATE' privileges, but this scares me because then they would be able to update *any* user - even one for a different database.
    LVL 14

    Expert Comment

    I must admit I have never found a need to give anyone other than root permissions to create users. I find that it's best to keep track of who your db users are and why they're being created.

    Have you tried the same queries using abc123@localhost?

    I just tested creating a user with usage only, but with grant option and had the same problem. I'd say that you need more privileges than is safe to give a normal user in order to let them create other users.

    It might be best to make your users request new users through you instead of being able to create them themselves.

    Author Comment

    I was hoping to minimize my involvement once I got their db setup - my job is *not* database management and I don't want to get stuck spending too much time on it.   But it looks like it might not be possible to do exactly what I want.

    I think I'm going to setup my script to create an additional user account for each new databse with only SELECT privileges to that database.  From there, the owner can grant INSERT or whatever privileges.
    LVL 14

    Accepted Solution

    I agree. There is no reason for your users to be able to create new users. Just give them one user with all privs on their particular db and another user with SELECT, INSERT, UPDATE, DELETE. Then one more with SELECT only.

    This will cover their needs and they will not need to mess around with users.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Suggested Solutions

    All XML, All the Time; More Fun MySQL Tidbits – Dynamically Generate XML via Stored Procedure in MySQL Extensible Markup Language (XML) and database systems, a marriage we are seeing more and more of.  So the topics of parsing and manipulating XM…
    Both Easy and Powerful How easy is PHP? (  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now