Harish Yadav Pyadindi
Harish Yadav Pyadindi

Reputation: 67

Create an user in mysql with readonly access

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

GRANT SELECT ON `databasename`.* TO 'username'@'localhost';

Upvotes: 5

Views: 24123

Answers (3)

B. Naga Lakshmi
B. Naga Lakshmi

Reputation: 637

create read only user

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

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

Upvotes: 5

Mohammed Noor Alam
Mohammed Noor Alam

Reputation: 452

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

Upvotes: 21

Ashish Kalekar
Ashish Kalekar

Reputation: 67

Try this

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

> FLUSH PRIVILEGES;

Upvotes: -1

Related Questions