6
CREATE USER 'username'@'localhost' IDENTIFIED BY 'Password';

GRANT SELECT ON `databasename`.* TO 'username'@'localhost';
2
  • 6
    What is the issue? and what is the question? Commented Dec 28, 2021 at 5:18
  • Such a confusing way to begin this question... Commented Oct 15, 2024 at 19:33

3 Answers 3

23

Create new user

CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'password';

GRANT type_of_permission ON database_name

GRANT SELECT ON database_name.table_name TO 'username'@'localhost';

Once you have finalized the permissions that you want to set up for your new users, always be sure to reload all the privileges.

FLUSH PRIVILEGES;

Here is a short list of other common possible permissions that can be used.

ALL PRIVILEGES- as we saw previously, this would allow a MySQL user full access to a designated database (or if no database is selected, global access across the system)

CREATE- allows them to create new tables or databases

DROP- allows them to them to delete tables or databases

DELETE- allows them to delete rows from tables

INSERT- allows them to insert rows into tables

SELECT- allows them to use the SELECT command to read through databases

UPDATE- allow them to update table rows

Sign up to request clarification or add additional context in comments.

Comments

7

create read only user

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

GRANT SELECT, SHOW VIEW ON database_name.* TO 'user_name'@'%';

Comments

-1

Try this

> GRANT SELECT, SHOW VIEW ON databasename.* TO 'username'@'localhost' IDENTIFIED BY 'password';

> FLUSH PRIVILEGES;

1 Comment

FWIW this didn't work for me on 8.0.28. I had to expressly create the user first using the CREATE USER command, and then grant privileges to it, like @Mohammed Noor Alam did in his answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.