How To Create A Read-Only MySQL User? | Code2Night
Code2night
  • Home
  • Blogs
  • Guest Posts
  • Tutorial
  • Post Blog
  • Register
  • Login
  1. Home
  2. Blogpost

How to create a read-only MySQL user

Date- Jan 05,2023

5857

Hello, guys, and welcome to Code2Night. In this article, we will explore the process of creating a read-only MySQL user. MySQL is a popular open-source relational database management system used by developers and organizations worldwide. By creating a readable user, you can grant limited access to your database, allowing users to view and retrieve data without the ability to modify or delete it.

Managing user privileges is an essential aspect of database security, as it enables you to control who can perform specific operations on your database. In many scenarios, it is necessary to provide access to certain users or applications to maintain data integrity and prevent unauthorized changes.

Throughout this article, we will walk you through the steps required to create a read-only user. We will start by discussing the concept of user privileges and why it is crucial to grant appropriate permissions. Then, we will delve into the process of creating a new user and assigning the necessary readable privileges using both the command-line interface and popular management tools.

Whether you are a beginner starting or an experienced developer looking to enhance your database security practices, this article will provide you with the knowledge and guidance to create a read-only database user effectively.

Step 1. Open the workbench and log in as a MySQL administrator

Step 2. Create a new MySQL user account.

CREATE USER 'report'@'%' IDENTIFIED BY '12345';

The % in the command above means that the user report can be used to connect from any host. You can limit access by defining the host from where the user can connect. Omitting this information will only allow the user to connect from the same machine.

Step 4. Grant the SELECT privilege to the user.

GRANT SELECT ON DatabaseName.* TO 'report'@'%'; 

Step 5. After creating a new MySQL user account then you have to Connect to a Database with MySQL Workbench follow the link for "How to Connect to a Database with MySQL Workbench" 

https://code2night.com/Blog/MyBlog/How-to-Connect-to-a-Database-with-MySQL-Workbench

read-only

Step 6. when we delete any record from the database we are getting error "delete from city where ID=1 Error Code: 1142. DELETE command denied to user 'report'@'localhost' for table 'city' 0.000 sec" because the user has only read-only permission 



Comments

Tags

LinkedinLogin
LinkedinProfile
GetLinkedinProfile
C#
Aspnet
MVC
Linkedin
ITextSharp
Export to Pdf
AspNet Core
AspNet
View to Pdf in Aspnet
Model Validation In ASPNET Core MVC 60
Model Validation
Model Validation In ASPNET Core MVC
Model Validation In ASPNET
Image Compression in AspNet
Compress Image in c#
AspNet MVC
Free Download for Youtube Subscribers!

First click on Subscribe Now and then subscribe the channel and come back here.
Then Click on "Verify and Download" button for download link

Subscribe Now | 1180
Download
Support Us....!

Please Subscribe to support us

Thank you for Downloading....!

Please Subscribe to support us

Continue with Downloading
Be a Member
Join Us On Whatsapp Join Us On Facebook

Welcome To Code2night, A common place for sharing your programming knowledge,Blogs and Videos

  • Panipat
  • info@Code2night.com

Links

  • Home
  • Blogs
  • Tutorial
  • Post Blog

Popular Tags

Copyright © 2025 by Code2night. All Rights Reserved

  • Home
  • Blog
  • Login
  • SignUp
  • Contact
  • Terms & Conditions
  • Refund Policy
  • About Us
  • Privacy Policy
  • Json Beautifier
  • Guest Posts