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.


Use this query to creating user account that can be connect from the localhost or from another server

CREATE USER 'bob'@'%' IDENTIFIED BY 'password';
  • But % does not include localhost.
    – Rick James
    Mar 14 '18 at 4:26
  • CREATE USER 'root'@'%' IDENTIFIED BY 'Password'; GRANT ALL PRIVILEGES ON * . * TO 'root'@'localhost'; FLUSH PRIVILEGES; Mar 15 '18 at 7:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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