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?
Join Stack Overflow to learn, share knowledge, and build your career.
|
Try this to create the user:
Try this to give it access to the database
If you are running the code/site accessing MySQL on the same machine, hostname would be localhost. Now, the break down.
|
|||||||||||||||||||||
|
SyntaxTo create user in MySQL/MariaDB 5.7.6 and higher, use
then to grant all access to the database (e.g.
Where Then to reload newly assigned permissions run:
ExecutingTo run above commands, you need to run To run from shell, use
or print statement from the standard input:
If you've got Access denied with above, specify
Shell integrationFor people not familiar with MySQL syntax, here are handy shell functions which are easy to remember and use (to use them, you need to load the shell functions included further down). Here is example:
To use above commands, you need to copy&paste the following functions into your rc file (e.g.
|
|||||||||||||||||
|
To create a user and grant all privileges on a database.Log in to MySQL:
Now create and grant
Anonymous user (for local testing only)Alternately, if you just want to grant full unrestricted access to a database (e.g. on your local machine for a test instance, you can grant access to the anonymous user, like so:
|
|||||||||||||||||
|
|
You can create new users using the CREATE USER statement, and give rights to them using GRANT. |
|||||
|
ignore -p option, if mysql user has no password or just press "[Enter]" button to by-pass. strings surrounded with curly braces need to replaced with actual values. |
|||
|
|
|
The below command will work if you want create a new user give him all the access to a specific database(not all databases in your Mysql) on your localhost.
This will grant all privileges to one database Check what permissions that above command issued to that user by running the below command.
Just in case, if you want to limit the user access to only one single table
|
|||||
|
protected by Gilbert Le Blanc Feb 25 '13 at 17:10
Thank you for your interest in this question.
Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).
Would you like to answer one of these unanswered questions instead?