VillageSQL is a drop-in replacement for MySQL with extensions.
All examples in this guide work on VillageSQL. Install Now →
Creating Users
@'localhost' part is the host restriction — this account can only connect from the local machine. Common host patterns:
'alice'@'localhost' and 'alice'@'%' are two distinct accounts, even though the username is the same.
Granting Privileges
database.table notation:
*.*— all databases, all tables (global)myapp.*— all tables in themyappdatabasemyapp.orders— only theorderstable
Privilege Levels
Common privileges:
Viewing Grants
Revoking Privileges
ERROR 1141: There is no such grant defined for user. The user retains any privileges granted at other levels — revoking SELECT ON myapp.* does not remove SELECT ON myapp.orders if that was granted separately.
Changing Passwords
Roles (MySQL 8.0+)
Roles are named collections of privileges. Instead of granting individual privileges to each user, grant a role.Dropping Users
Least-Privilege Best Practices
Give each account only the privileges it needs:- Application read replicas:
SELECTonly - Application write account:
SELECT,INSERT,UPDATE,DELETE - Application schema account (migrations): add
CREATE,ALTER,DROP,INDEX - DBA account:
ALL PRIVILEGESon*.* - Never grant
SUPERorALLto application accounts
app.example.com should use 'appuser'@'app.example.com', not 'appuser'@'%'.
Frequently Asked Questions
Does MySQL flush grants automatically?
All changes viaCREATE USER, GRANT, REVOKE, and ALTER USER take effect immediately — no FLUSH PRIVILEGES needed. FLUSH PRIVILEGES is only necessary if you modify the grant tables directly with INSERT/UPDATE (which you shouldn’t do).
What’s the difference between localhost and 127.0.0.1?
localhost in MySQL refers to the Unix socket connection (local file socket), not the network loopback. 127.0.0.1 is the TCP loopback. If your client connects via TCP even on the same machine, use 127.0.0.1 as the host restriction.
Troubleshooting
See also
- MySQL Security Hardening — server-level security that complements user privileges

