MySQL password setting application and code

Source: Internet
Author: User

The following articles mainly describe how to set a correct password for the MySQL database. We all know that setting a password for MySQL often occurs in actual operations, if you are interested in the actual operation of setting passwords for MySQL, you can browse the following article.

The example in the previous section illustrates an important principle: When you use an INSERT or UPDATE statement to store a non-empty PASSWORD, you must use the PASSWORD () function to encrypt it. This is because passwords are stored in encrypted form in the user table, rather than plain text. If you forget this fact, you may try to set a password for MySQL like this:

 
 
  1. shell> mysql -u root mysql   
  2. mysql> INSERT INTO user (Host,User,Password) VALUES('%','jeffrey','biscuit');   
  3. mysql> FLUSH PRIVILEGES 

The result is that the plain text value 'biscuit' is stored in the user table as the password. When jeffrey tries to use this PASSWORD to connect to the server, mysql uses PASSWORD () to encrypt it and send the result to the server, the server compares the values in the user table (the plain text value is 'biscuit') with the encrypted password (instead of 'biscuit'). The comparison fails and the server rejects the connection:

 
 
  1. shell> mysql -u jeffrey -pbiscuit test  
  2. Access denied 

Because when they are inserted into the user table, the password must be encrypted. On the contrary, the INSERT statement should be specified as follows:

 
 
  1. mysql> INSERT INTO user (Host,User,Password)  
  2. VALUES('%','jeffrey',PASSWORD('biscuit')); 

When you use the set password statement, you must also use the PASSWORD () function:

 
 
  1. mysql> SET PASSWORD FOR jeffrey@"%" = PASSWORD('biscuit');  

If you use the GRANT... identified by statement or mysqladmin password command to set a PASSWORD for MySQL, the password () function is unnecessary. They all consider encrypting your password. You can specify a password like this ':

 
 
  1. mysql> GRANT USAGE ON *.* TO jeffrey@"%" IDENTIFIED BY 'biscuit'; 

Or

 
 
  1. shell> mysqladmin -u jeffrey password biscuit  

Note: PASSWORD () is not encrypted in the same way as the Unix PASSWORD. You should not assume that if your Unix PASSWORD is the same as your MySQL PASSWORD, PASSWORD () will cause the same encryption value as the one stored in the Unix PASSWORD File. See MySQL user name and password 6.2.

 
 
  1. set password for root@localhost=password('yournewpassword') 

The above content is an introduction to MySQL password settings. I hope you will get some benefits.

Original article title: MySQL: how to set a password

Connection: http://www.cnblogs.com/linlu11/archive/2009/11/07/1598259.html

Related Article

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.