MySQL security starts with user account management. Each user account is identified by a username and the host from which they can connect. Understanding how to create, modify, and remove user accounts is the foundation of database security.
Creating Users
The CREATE USER statement creates a new account. The account identifier is in the form 'user'@'host'. Using 'localhost' restricts the account to local connections only, while '%' allows connections from any host.
Authentication Plugins
MySQL 8.0 uses caching_sha2_password as the default authentication plugin. Older clients may need mysql_native_password. Always use strong, randomly generated passwords for database accounts.
- Use 'localhost' instead of '%' whenever possible
- Create separate accounts for each application
- Never use the root account in application code
- Rotate passwords regularly