Hands-on Lab·MySQL
MySQL Privileges and GRANT
Grant SELECT on one schema and the account can read it and nothing else. The write attempt that follows fails with a different error from the last guide's - 1142, not 1044 - and the difference is the diagnosis.
Users and Privileges Guide 17 of 45 Beginner
- OSUbuntu 26.04 LTS
- MySQL8.4.10-0ubuntu0.26.04.1
- Authcaching_sha2_password
- TimeAbout 13 min
GRANT no longer creates accounts implicitly in MySQL 8; CREATE USER first is required. Older scripts that rely on the implicit form fail on 8.x.
| Server Name | IP Address | OS | Roles | CPU | RAM | HDD |
|---|---|---|---|---|---|---|
| db-a01 | 192.168.0.81 | Ubuntu 26.04 LTS | Primary / Source / Replica Set Member 1 | 2 Core | 4 GB | 50 GB |
This guide includes
Use this when an account needs exactly enough access and no more. This matters because the errors are the diagnosis - a missing database grant and a missing write grant produce different numbers, and reading them beats guessing.
- granting read access to one schema
- reading the grants back, which is the authoritative list
- confirming the read now works where it failed a moment ago
- trying to write, and getting a different error that teaches the diagnosis
Before you start
- The
reportingaccount from the previous guide.
-
Grant read access to one schema
-
Read the grants back
-
Confirm the read works
-
Try to write, and get a different error