Home > Database > Mysql Tutorial > 如何设置MYSQL的口令_MySQL

如何设置MYSQL的口令_MySQL

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-01 13:55:09
Original
1143 people have browsed it

当你使用INSERT或UPDATE语句存储一个非空的口令时,你必须使用PASSWORD()函数加密它。这是因为在user表中以加密形式存储口令,而不是作为纯文本。如果你忘记这个事实,你可能像这样试图设置口令:

shell> mysql -u root mysql

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

mysql> FLUSH PRIVILEGES

结果是纯文本值'biscuit'作为口令被存储在user表中。在用户jeffrey试图用这个口令连接服务器时,mysql客户用PASSWORD()加密它并且将结果送给服务器,服务器比较在user表中的值(它是纯文本值'biscuit')和加密的口令(而不是 'biscuit'),比较失败并且服务器拒绝连接:

shell> mysql -u jeffrey -pbiscuit test

Access denied

因为当他们被插入user表时,口令必须被加密,相反,INSERT语句应该象这样被指定:

mysql> INSERT INTO user (Host,User,Password)

VALUES('%','jeffrey',PASSWORD('biscuit'));

当你使用SET PASSWORD语句时,你也必须使用PASSWORD()函数:

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

如果你使用GRANT ... IDENTIFIED BY语句或mysqladmin password命令设置口令,PASSWORD()函数是不必要的。他们都考虑到为你加密口令,多以你可像这样指定一个口令'biscuit':

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

或 shell> mysqladmin -u jeffrey password biscuit

注意: PASSWORD()不不同于Unix口令加密方法。

 

Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template