How to Set a MYSQL password

Source: Internet
Author: User

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.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.