MySQL Grant Generator
CREATE USER and a least-privilege GRANT for one database
-
1Enter data
Enter content, paste text or load a file from disk. -
2Click the button
The tool will immediately process your data in the browser. -
3Get the result
Copy the finished text or save the file to your device.
return "Result ready in 0.1s";
}
The result contains a password placeholder for local replacement. The tool does not accept real secrets. The % host means every address.
Rate this tool:
Related tools
Other tools you may find usefulMySQL GRANT generator with least privilege by default
The generator prepares CREATE USER and GRANT statements for one account, host, and MySQL database. Only SELECT is enabled by default because every additional permission should follow from a concrete application requirement. The database name is quoted as an identifier, while the username, host, and password are handled as SQL literals.
A dedicated application account limits the impact of leaked credentials. Instead of connecting a service as root, you can give it access to one database and only the required operations. Prepare web server rules with the .htaccess generator, describe container services with the Docker Compose generator, and schedule administrative work with the crontab generator.
Identifiers and literals are different SQL elements
The database name in the ON clause is an identifier and receives backticks: `app_db`.*. A MySQL account name consists of two literals: 'app_user'@'localhost'. The generator does not accept a real password: it always emits a fixed placeholder quoted as an SQL literal. User, host, and database values pass strict validation before quoting, while control characters and syntax fragments are rejected.
CREATE USER 'app_user'@'localhost'
IDENTIFIED BY 'CHANGE_ME_STRONG_PASSWORD';
GRANT SELECT ON `app_db`.* TO 'app_user'@'localhost';
User and database names deliberately use a conservative format: ASCII letters, digits, and underscores. This restriction reduces confusion between a name and SQL syntax. Quoting should not be removed merely because the current value contains no special character.
Least privilege instead of ALL PRIVILEGES
SELECT is sufficient for a reporting process and is a safe starting point. A CRUD application may additionally require INSERT, UPDATE, and DELETE. Permissions such as CREATE, DROP, ALTER, and INDEX normally belong to a separate migration account. REFERENCES covers foreign-key constraints, while EXECUTE covers stored routines. The generator does not offer ALL PRIVILEGES, keeping each choice explicit.
| Privilege | Typical purpose | Risk |
|---|---|---|
SELECT | Reading data and reports | Exposure of accessible database content |
INSERT, UPDATE, DELETE | Application operations | Changing or removing records |
CREATE, ALTER, INDEX | Schema migrations | Changing structure and performance |
DROP | Removing objects | Irreversible table loss |
EXECUTE | Stored routines | Behavior determined by routine definitions |
The MySQL account host
In MySQL, 'app_user'@'localhost' and 'app_user'@'%' are different accounts. localhost limits access to the database server, a specific IP address or DNS name narrows the network source, while % accepts every host. The generator permits a standalone % as an explicit decision but rejects mixed wildcard patterns, whitespace, and SQL fragments. In production, choose the most precise host and add firewall restrictions.
CHANGE_ME_STRONG_PASSWORD placeholder, which must be replaced locally before execution, outside the browser and Livewire layer.Why WITH GRANT OPTION and FLUSH PRIVILEGES are absent
WITH GRANT OPTION would let the new account delegate its own permissions to other users. A normal application account should not have that ability, so the generator never emits the clause. Statements managed by the MySQL server do not require FLUSH PRIVILEGES after CREATE USER or GRANT either; adding it would be redundant and may require another global administrative privilege.
The generator uses CREATE USER without IF NOT EXISTS. If the account already exists, the server reports an error rather than suggesting that the entered password was applied. Use an intentional ALTER USER for an existing account and inspect current permissions with SHOW GRANTS.
A safe usage procedure
- Create a separate account for one application or process and select the narrowest possible host.
- Choose one database and only the operations required by the application's actual queries.
- Generate the statements, then replace the placeholder with a strong secret only in a protected local file.
- Review the result as an administrator, run it in a controlled session, and remove secrets from shell history.
- Confirm the result with
SHOW GRANTS FOR 'user'@'host'and a connection test using the application account.
Frequently asked questions
Is the % host safe?
It means every source address and is usually too broad. Use it only deliberately, together with network restrictions and strong authentication.
Why is only SELECT enabled by default?
It is the narrowest useful read-only variant. Data-changing and schema permissions should be added only after confirming actual application requirements.
Can this generator change an existing account password?
No. CREATE USER intentionally reports a conflict. Use ALTER USER directly in a secured administrative session for a controlled password change.
Why quote a simple name such as app_db?
Quoting unambiguously marks an identifier and prevents keyword collisions. Validation and quoting are separate, complementary protections.
How do I revoke a privilege later?
Use REVOKE for the exact account and scope, then inspect the result with SHOW GRANTS. FLUSH PRIVILEGES is not required.