How to create read-only user in MySQL

by Daniel Pham
Published: Updated:

This article will show you how to create read-only user in MySQL.

In which case do you need to use user read-only in MySQL? Normally in monitor systems, at the dashboard, you only need to use a read-only user.

This user will read data from the database and display information to the dashboards.

Commands to create a read-only user

You execute the following commands to create a user with SELECT permission in MySQL.

create a read-only user in mysql
Create a read-only user in MySQL.

First, use the following command to create youruser user with the ip login is localhost.

CREATE USER 'youruser'@'localhost' IDENTIFIED BY 'yourpassword';

Next, use the following command to create youruser user with the ip login as your remote ip. For example, the remote ip is 192.168.100.10.

CREATE USER 'youruser'@'192.168.100.10' IDENTIFIED BY 'yourpassword';

Next, use the following command to grant SELECT permission (equivalent to read-only) to the user who just created your database.

Recommended Reading: How to install MariaDB 10.3 in Debian 8

GRANT SELECT ON yourdatabase . * TO 'youruser'@'localhost';
GRANT SELECT ON yourdatabase . * TO 'youruser'@'192.168.100.10';

And finally, you use the flush command in mysql to apply a new user.

FLUSH PRIVILEGES;

Conclusion

So you’ve created the read-only user in MySQL. The commands are quite simple but sometimes you won’t remember how to do it. Even I myself.

Hope it will be useful for you at some time.

(This is an article from my old blog that has been inactive for a long time, I don’t want to throw it away so I will keep it and hope it helps someone).

0 0 votes
Article Rating

You may also like

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments

DevOps Lite is a personal blog specializing in technology with main topics about DevOps, DevSecOps, SRE and System Administrator. Articles are shared for free and contributed to the community.

SUPPORT US

FOLLOW US

Subscribe my Newsletter for new blog posts. Stay updated from your inbox!

© 2021-2024 DevOpsLite.com – All rights reserved.

Please write sources “DevOpsLite.com” when using articles from this website.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More

2
0
Would love your thoughts, please comment.x
()
x

Adblock Detected

Please support us by disabling your AdBlocker extension from your browsers for our website.