MySQL Restrict user to register only one database

database, mysql

Solution

Are you asking how you do this via script? In MySQL Admin you can grant rights by Database/Schema and a user can only connect to the database he has at least the right to SELECT.

If you want to do it without GUI you can do it by command line. From the docs (http://dev.mysql.com/doc/refman/5.1/en/grant.html):

GRANT SELECT, INSERT ON mydb.* TO 'someuser'@'somehost';

The command above grants SELECT and INSERT on the database "mydb" for the user "someuser" that tries to connect from "somehost" for all tables contained in the database. Of course you can set rights in more Detail, for single tables for example or to grant the right to connect from any host.

Or are you looking for a way to do this via phpmyadmin? Also there you can grant rights by database or overall but as I experienced you have to look closely sine do not see this right away and sometimes set the rights for all databases by accident.

Probably the best way is to take away all rights and then start from scratch so you do not miss to remove any (works for MySQL 4.1.2 and newer)

REVOKE ALL PRIVILEGES, GRANT OPTION FROM user 

Problem

I am Stuck at a point where Requirement is : I have created new user in mysql with insert,delete,update,select & create permission now i want if someone register database with this new user he should only able to register only one DATABASE from my list of databases .... Restrict new user to register only one Database .... from my db list.... Thanks

Original source