Command method. Note that each line is followed by one; indicates that a command statement ends.
Format: grant select on database. * To username @ login host identified by "password"
Example 1: Add a user named "test1" with the password "ABC" so that the user can log on to any host and have the permission to query, insert, modify, and delete all databases. First, use the root user to connectMySQLAnd then type the following command:
Grant select, insert, update, delete on *. * To test1 @ "%" identified by "ABC ";
However, the User Added in Example 1 is very dangerous. If you want someone to know the password of test1, then he can log on to your computer on the Internet.MySQLThe database can do whatever you want. For the solution, see Example 2.
Example 2: Add a user named "Test2" with the password "ABC" so that the user can only log on to localhost, you can also query, insert, modify, and delete the database mydb (localhost refers to the local host, that isMySQLIn this way, the user knows the password of Test2 and cannot directly access the database from the Internet.MySQLThe web page on the host is accessed.
Grant select, insert, update, delete on mydb. * To Test2 @ localhost identified by "ABC ";
If you do not want Test2 to have a password, you can run another command to remove the password.
Grant select, insert, update, delete on mydb. * To Test2 @ localhost identified "";