I'm new to MySQL administration. I want to create a new user in MySQL and give it full access only to 1 database, say dbTest, that I create. What would be the MySQL commands to do that?
Try this:
GRANT ALL PRIVILEGES ON dbTest.* To 'user'@'hostname' IDENTIFIED BY 'password';
If you are running the code/site accessing MySQL on the same machine, hostname would be localhost.
Now, the break down.
GRANT
- This is the command used to create users and grant rights to databases, tables, etc.
ALL PRIVILEGES
- This tells it the user will have all standard privileges. This does not include the privilege to use the GRANT command however.
dbtest.*
- This instructions MySQL to apply these rights for the use onto the full dbtest database. You can replace the * with specific table names or store routines if you wish.
TO 'user'@'hostname'
- 'user' is the of the user account you are creating. Note: You must have the single quotes in there. 'hostname' tells MySQL what hosts the user can connect from. If you only want it from the same machine, use localhost
IDENTIFIED BY 'password'
- As you would have guessed, this sets the password for that user.
You can create new users using the CREATE USER statement, and give rights to them using GRANT.
You can use MySQL commands for that kind of actions or you can use some softwares like HeidiSQL or, Toad for MySQL. I suggest you to use that kind of softwares to manage your MySQL.