Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm using MySQL and I need to create an account that can connect from either the localhost or from another server, i.e. So I am doing:

CREATE USER 'bob'@'localhost' IDENTIFIED BY 'password123';
CREATE USER 'bob'@'' IDENTIFIED BY 'password123';
GRANT SELECT, INSERT, UPDATE, DELETE on MyDatabse.* to 'bob'@'localhost', 'bob'@'';

This works fine, but is there any more elegant way to create a user account that is linked to multiple IPs or does it need to be done this way?

My main worry is that in the future, permissions will be updated form 'bob' account and not the other.

share|improve this question
I wanted to fix the missing apostrophe after but ServerFault didn't let me. Edits must be at least 6 characters. Fail. – Josef Sábl Aug 7 '14 at 8:34
up vote 12 down vote accepted

If you want to restrict to host and do not want to specify based on a subnet or wildcard using %, that's the only way to do it. More details are available in the MySQL documentation.

I am still trying to find ways to eliminate overhead when managing authentication to large MySQL installations and have yet to find a perfect solution.

share|improve this answer

According to your requirement,

Let's start by making a new user called "chaminda" within the MySQL shell:

CREATE USER 'chaminda'@'%' IDENTIFIED BY 'password';

The first thing to do is to provide the user with necessary permission and here I have given all permission to the particular user.

GRANT ALL PRIVILEGES ON * . * TO 'chaminda'@'%';

Reload all the privileges.


Note: Here host Name = % and that means you can access this database server from any host. Giving all privileges to the user is a big risk and that's not a best practice. Further you can replace user 'chaminda' to 'bob'.

share|improve this answer

MySQL allows multiple wildcards in one row. A possible solution is to set Host for user Bob to be



share|improve this answer
That is not what the documentation is saying. As listed in the table, the / is a netmask. If there is a way to list multiple wildcards in the host definition, that isn't the way to do it. – majikman Jan 14 '15 at 21:33

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.