MySQL Default has a root user, but this user rights are too large, generally only in the management of the database when used. If you are connecting to a MySQL database in your project, it is recommended that you create a new user with a smaller permission to connect.
You can create a new user for MySQL by entering the following command in MySQL command line mode:
CREATE USER username identified by ' password ';
The new user is created, but at this point, if logged in as this user, will be an error, because we have not assigned the appropriate permissions for this user, the command to assign permissions are as follows:
GRANT all privileges on * * to ' username ' @ ' localhost ' identified by ' password ';
Grant username all permissions to the user on all databases.
If you find that the permission you just gave is too large, if we just want to grant it permissions on a database, then we need to switch to the root user revoke the permissions just now, re-authorize:
Evoke all privileges on * * from ' username ' @ ' localhost '; GRANT all privileges the wordpress.* to ' username ' @ ' localhost ' identified by ' password ';
You can even specify that the user can only execute select and update command:
GRANT SELECT, UPDATE on wordpress.* to ' username ' @ ' localhost ' identified by ' password ';
This way, to username log in to MySQL again, only the wordpress database is visible to it, and if you only grant it select permission, then it cannot execute the delete statement.
In addition, each time you adjust permissions, you typically need to perform the following statement refresh permissions:
FLUSH privileges;
Delete the user you just created:
DROP USER [email protected];
MySQL User management and Rights management