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"
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