Skip to main content
Login Register
Code2night
  • Home
  • Blog Archive
  • Learn
    • Tutorials
    • Videos
  • Interview Q&A
  • Languages
    • Angular Angular js ASP.NET Asp.net Core ASP.NET Core, C# C C# C#, ASP.NET Core, Dapper
      C#, ASP.NET Core, Dapper, Entity Framework DotNet HTML/CSS Java JavaScript Node.js Python Python 3.11, Pandas, SQL
      Python 3.11, SQL Python 3.11, SQLAlchemy Python 3.11, SQLAlchemy, SQL Python 3.11, SQLite React Security SQL Server TypeScript
  • Post Blog
  • Tools
    • Beautifiers
      JSON Beautifier HTML Beautifier XML Beautifier CSS Beautifier JS Beautifier SQL Formatter
      Dev Utilities
      JWT Decoder Regex Tester Diff Checker Cron Explainer String Escape Hash Generator Password Generator
      Converters
      Base64 Encode/Decode URL Encoder/Decoder JSON to CSV CSV to JSON JSON to TypeScript Markdown to HTML Number Base Converter Timestamp Converter Case Converter
      Generators
      UUID / GUID Generator Lorem Ipsum QR Code Generator Meta Tag Generator
      Image Tools
      Image Converter Image Resizer Image Compressor Image to Base64 PNG to ICO Background Remover Color Picker
      Text & Content
      Word Counter PDF Editor
      SEO & Web
      SEO Analyzer URL Checker World Clock
  1. Home
  2. Blog
  3. SQL Server
  4. How to create a read-only MySQL user

How to create a read-only MySQL user

Date- Jan 05,2023 Updated Mar 2026 10243

Overview of MySQL User Privileges

MySQL user privileges are essential to maintaining security and control over your database. User privileges define what operations a user can perform, ranging from read-only access to full administrative rights. Understanding these privileges is crucial for ensuring that sensitive data remains protected while still being accessible to authorized users.

In a typical scenario, you may want to allow developers, analysts, or applications to access data without allowing them to alter it. This is where the concept of a read-only MySQL user comes into play. By granting SELECT privileges, you ensure that users can retrieve data without the risk of accidental deletions or modifications.

Prerequisites

Before you begin the process of creating a read-only MySQL user, ensure you have the following:

  • A MySQL server installed and running.
  • Access to MySQL with administrative privileges.
  • MySQL Workbench or any other MySQL client for managing users and permissions.

Step 1: Open MySQL Workbench and Log In

To start, open MySQL Workbench and log in using your administrator credentials. This step is crucial as only an administrator can create new users and assign privileges.

Step 2: Create a New MySQL User Account

To create a new user account, execute the following SQL command:

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

The % symbol indicates that the user can connect from any host. If you want to restrict access to a specific host, replace % with the hostname or IP address of that machine. For example, to allow access only from localhost, use:

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

Step 3: Grant SELECT Privilege to the User

Next, you need to grant the SELECT privilege to the newly created user. This privilege allows the user to read data from the database:

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

Replace DatabaseName with the actual name of your database. This command permits the user to read all tables in the specified database.

Step 4: Verify User Privileges

After granting privileges, it's a good practice to verify that the user has the correct permissions. You can check the privileges assigned to the user with the following command:

SHOW GRANTS FOR 'report'@'%';

This command will display the privileges assigned to the user, confirming that they have read-only access.

Step 5: Connect to a Database with MySQL Workbench

To connect to the database with the new user, follow the instructions in the article How to Connect to a Database with MySQL Workbench. This step is essential to test the new user account and ensure it functions as intended.

Step 6: Testing Read-Only Access

Once connected as the read-only user, you can attempt to run various SQL commands. For example, executing a SELECT statement should return results:

SELECT * FROM city;

However, if you try to delete a record, you should encounter an error message indicating that the user does not have permission:

DELETE FROM city WHERE ID=1;

This command will result in an error similar to: Error Code: 1142. DELETE command denied to user 'report'@'localhost' for table 'city'.

read-only

Edge Cases & Gotchas

While creating a read-only user is generally straightforward, there are some edge cases and common pitfalls to be aware of:

  • Default Privileges: If you create a user without specifying host access, the user may only be able to connect from localhost. Ensure you specify the correct host if remote access is necessary.
  • Database Name Changes: If the name of the database changes, you will need to re-grant privileges to the user. Always check after any major changes to your database structure.
  • Permissions Inheritance: Be cautious with inherited permissions when using roles. Ensure that roles do not grant more privileges than intended.

Performance & Best Practices

When managing user privileges in MySQL, consider the following best practices:

  • Principle of Least Privilege: Always grant the minimum permissions necessary for a user to perform their tasks. This minimizes the risk of accidental data modification.
  • Regular Audits: Periodically review user accounts and their privileges. Remove any accounts that are no longer needed.
  • Use Roles: For complex applications with multiple users, consider using roles to group permissions. This simplifies management and reduces errors.

Conclusion

Creating a read-only MySQL user is a critical step in securing your database. By following the steps outlined in this article, you can effectively manage user access while maintaining data integrity.

  • Understand the importance of user privileges in MySQL.
  • Follow the step-by-step process to create a read-only user.
  • Test the user's permissions to ensure they function as expected.
  • Be aware of edge cases and best practices for managing user accounts.
How to create a read-only MySQL user

S
Shubham Batra
Programming author at Code2Night โ€” sharing tutorials on ASP.NET, C#, and more.
View all posts โ†’

Related Articles

Batch Script for Creating Database backups from Sql server
Apr 30, 2022
How to Connect to a Database with MySQL Workbench
Jan 04, 2023
How to find all procedures having table reference in Sql server
Jan 13, 2023
How to find all tables by column name
Jan 13, 2023
Previous in SQL Server
How to Connect to a Database with MySQL Workbench
Next in SQL Server
How to Return Query Results as a Comma Separated in MySQL
Buy me a pizza

Comments

On this page

๐ŸŽฏ

Interview Prep

Ace your SQL Server interview with curated Q&As for all levels.

View SQL Server Interview Q&As

More in SQL Server

  • Converting commas or other delimiters to a Table or List in … 6452 views
  • How to read json in Sql Server 6048 views
  • Multiple rows to one comma separated value in Sql Server 5894 views
  • How to rename table column in sql server 5779 views
  • How to Return Query Results as a Comma Separated in MySQL 5421 views
View all SQL Server posts โ†’

Tags

AspNet C# programming AspNet MVC c programming AspNet Core C software development tutorial MVC memory management Paypal coding coding best practices data structures programming tutorial tutorials object oriented programming Slick Slider StripeNet
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 | 1770
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
Code2Night

A community platform for sharing programming knowledge, tutorials, and blogs. Learn, write, and grow with developers worldwide.

Panipat, Haryana, India
info@code2night.com
Quick Links
  • Home
  • Blog Archive
  • Tutorials
  • About Us
  • Contact
  • Privacy Policy
  • Terms & Conditions
  • Guest Posts
  • SEO Analyzer
Dev Tools
  • JSON Beautifier
  • HTML Beautifier
  • CSS Beautifier
  • JS Beautifier
  • SQL Formatter
  • Diff Checker
  • Regex Tester
  • Markdown to HTML
  • Word Counter
More Tools
  • Password Generator
  • QR Code Generator
  • Hash Generator
  • Base64 Encoder
  • JWT Decoder
  • UUID Generator
  • Image Converter
  • PNG to ICO
  • SEO Analyzer
By Language
  • Angular
  • Angular js
  • ASP.NET
  • Asp.net Core
  • ASP.NET Core, C#
  • C
  • C#
  • C#, ASP.NET Core, Dapper
  • C#, ASP.NET Core, Dapper, Entity Framework
  • DotNet
  • HTML/CSS
  • Java
  • JavaScript
  • Node.js
  • Python
  • Python 3.11, Pandas, SQL
  • Python 3.11, SQL
  • Python 3.11, SQLAlchemy
  • Python 3.11, SQLAlchemy, SQL
  • Python 3.11, SQLite
  • React
  • Security
  • SQL Server
  • TypeScript
© 2026 Code2Night. All Rights Reserved.
Made with for developers  |  Privacy  ยท  Terms
Translate Page
We use cookies to improve your experience and analyze site traffic. By clicking Accept, you consent to our use of cookies. Privacy Policy
Accessibility
Text size
High contrast
Grayscale
Dyslexia font
Highlight links
Pause animations
Large cursor