NOTE: The SQL statement in the MySQL database is terminated by default with ";". Enter the command, the keyword can be uppercase or lowercase, but must be consistent, I prefer to use lowercase, personal habits bar.
There are three main ways of creating database users in MySQL:
1 by inserting data records into the user table of the MySQL library (note: MySQL users are saved by default in the user table):
mysql> INSERT INTO User (NAME,PASSWD) VALUES (' Zwj ', ' ABCDEFG ');
Description
INSERT INTO: keyword
User: Table name, followed by field name in parentheses
Values: keyword, followed by the value of the field in parentheses
The user can view the built user:mysql> select * from Mysql.user;
In general, it is not recommended to use the above method to create a user (too amateur)
2 Creating a user using the Create USER statement:
Mysql>create user ' t100 ' @ ' 127.0.0.1 ' identified by ' t100 ';
Description
Create User: Keyword
T100: User Name
127.0.0.1: Source address, which means this machine, can also be written as a network segment such as: 192.168.10.%
Identified by: The keyword used to set the password, if omitted, indicates that the password is empty
After the user is established, authorization is required, otherwise most operations will not work except to connect to the database.
3 Create a user and grant permissions by using the GRANT statement:
Mysql> Grant Select on mysql.* to ' t100 ' @ ' 192.168.10.1 ' identified by ' t100 ';
Description
Grant: Keyword
Select: Permissions for Queries
On: Keywords
All tables under the Mysql.*:mysql library, * as wildcards represent all
The above statement means setting up a user t110 that allows clients from 192.168.10.1 to access the database and grant permissions to the query.
The user needs to refresh the permissions table after it is built:
Mysql>flush privileges;
View Permissions:mysql> show grants for ' T100 ' @ ' 192.168.10.1 ';
Revoke permissions:mysql> Revoke select on mysql.* from ' t100 ' @ ' 192.168.10.1 ';
The third way is the more common way to create users and authorizations.
This article from "10,000 years too long, seize" blog, please be sure to keep this source http://zengwj1949.blog.51cto.com/10747365/1881481
MySQL database four: Create user