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:
- shell> mysql -u root mysql
- mysql> INSERT INTO user (Host,User,Password) VALUES('%','jeffrey','biscuit');
- 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:
- shell> mysql -u jeffrey -pbiscuit test
- 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:
- mysql> INSERT INTO user (Host,User,Password)
- VALUES('%','jeffrey',PASSWORD('biscuit'));
When you use the set password statement, you must also use the PASSWORD () function:
- 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 ':
- mysql> GRANT USAGE ON *.* TO jeffrey@"%" IDENTIFIED BY 'biscuit';
Or
- 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.
- 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