If we only use the root user, there will be security risks.
1. User
1. User Information
Users in MySQL are stored in the user table of the system database mysql.
- host: Indicates which host the user can log in from. If it is localhost, it can only log in from the local machine
- user: username
- authentication_string: User password encrypted by password function
2. Create a user
create user 'username'@'login host/ip' identified by 'password';
3. Delete user
drop user 'username'@'hostname'
4. Modify user password
set password=password('new password'); //Change your own password
set password for 'username'@'hostname'=password('new password'); //The root user modifies the password of the specified user
2. Database permissions
1. Authorize the user
The newly created user does not have any permissions and needs to be authorized for the user.
grant permission list on library.object name to 'username'@'login location' [identified by 'password']
- *.* : Represents all objects (tables, views, stored procedures, etc.) of all databases in this system
- library.* : Represents all data objects (tables, views, stored procedures, etc.) in a database
- identified by optional. If the user exists, change the password while granting permission, if the user does not exist, create the user
2. Recycling permissions
Revoke permission list on library. Object name from 'username'@'login location';