Jump to content

Grant does not work when adding a new user in mysql


mathman540

Recommended Posts

Use CREATE USER first to create the user account, then grant it the privileges it needs.

create user 'webuser' identified by 'abc123';
grant all on  wordpress.table to 'webuser';

Your first two grants failed because you are creating a new user. 'webuser'@'localhost' is different from 'webuser'@'host' specified in your create user statement.

Your second two failed because you didn't specify a valid privilege type.

Edited by kicken
Link to comment
Share on other sites

Yes, See the documentation for the GRANT statement.  The privilege level can be specified as:

priv_level: {
    *
  | *.*
  | db_name.*
  | db_name.tbl_name
  | tbl_name
  | db_name.routine_name
}

So to set a privilege on an entire DB you would use the db_name.* syntax rather than the db_name.tbl_name syntax you are currently using.

 

Link to comment
Share on other sites

I tried the code you put above and find that when I put in the database name it is not working for me. The database name I used has been created in mysql. Also I don't know what db_name.routine_name is about. Am I suppose to put the splats in with the rest of the code? I have created a database called wordpress. I just can't create a single user to use with my word press. Your help is a bit confusing.

Edited by mathman540
still not clear
Link to comment
Share on other sites

In the documentation, it shows you the various options for the privilege level that you can specify.  The | separates the possible options and can be read like or.  So for the priv_level portion of the GRANT statement you can use either "*" (meaning default database), "*.*" (meaning all databases), "db_name.*" (meaning the entire database db_name), "db_name.tbl_name" (meaning table tbl_name in database db_name), "tbl_name" (meaning table tbl_name in the default database), or "db_name.routine_name" (meaning the routine routine_name in database db_name).

 

Since you want to grant privileges on a specific database, you would use the "db_name.*" option when writing your grant statement. That means you'd write your grant statement like so:

grant all on wordpress.* to 'webuser'@'host'

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.