When you useINSERTOrUPDATEYou must usePASSWORD()Function encryption. This is becauseuserThe table stores passwords in encrypted form instead of plain text. If you forget this fact, you may try to set a password like this:
Shell> mysql-u root mysql
Mysql> insert into user (Host, User, Password) VALUES ('%', 'Jeffrey ', 'biscuit ');
Mysql> FLUSH PRIVILEGES
The result is a plain text value.'biscuit'The password is stored inuserTable. In the userjeffreyWhen trying to connect to the server with this password,mysqlCustomerPASSWORD()Encrypt it and send the result to the server.userValue in the table (it is a plain text value'biscuit') And the encrypted password (Instead 'biscuit'), The comparison fails and the server rejects the connection:
Shell> mysql-u jeffrey-pbiscuit test
Access denied
Because when they are inserteduserTable, the password must be encrypted,On the contrary, INSERTThe statement should be specified as follows:
Mysql> insert into user (Host, User, Password)
VALUES ('%', 'Jeffrey ', PASSWORD ('biscuit '));
When you useSET PASSWORDYou must also usePASSWORD()Function:
Mysql> set password for jeffrey @ "%" = PASSWORD ('biscuit ');
If you useGRANT ... IDENTIFIED BYStatement ormysqladmin passwordCommand to set the password,PASSWORD()Functions are unnecessary. They all consider encrypting passwords for you. You can specify a password like this.'biscuit':
Mysql> grant usage on *. * TO jeffrey @ "%" identified by 'biscuit ';
Or shell> mysqladmin-u jeffrey password biscuit
Note:PASSWORD()It is not different from the Unix password encryption method.