-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCreateReadOnlyUser.sql
More file actions
29 lines (22 loc) · 849 Bytes
/
Copy pathCreateReadOnlyUser.sql
File metadata and controls
29 lines (22 loc) · 849 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/*
Purpose:
- Create a database-scoped, read-only MySQL account for reporting or diagnostics.
Safety:
- Changes state by creating a user and granting SELECT.
- Grants no global privileges and no GRANT OPTION.
Requirements:
- MySQL 8.0 or later.
- CREATE USER and GRANT OPTION privileges for the administrator running the script.
Customization:
- Replace every angle-bracket placeholder before execution.
- Prefer a specific host or subnet over '%'. Supply the password from a secret manager.
*/
CREATE USER '<REPORTING_USER>'@'<ALLOWED_HOST>'
IDENTIFIED BY '<STRONG_PASSWORD_FROM_SECRET_MANAGER>'
REQUIRE SSL;
GRANT SELECT, SHOW VIEW
ON `<DATABASE_NAME>`.*
TO '<REPORTING_USER>'@'<ALLOWED_HOST>';
SHOW GRANTS FOR '<REPORTING_USER>'@'<ALLOWED_HOST>';
-- Rollback, if required:
-- DROP USER '<REPORTING_USER>'@'<ALLOWED_HOST>';