Mysql的Hash密码

2013-04-17

MYSQL HASH的加密方式共分为两种。MYSQL4.1之前的版本中,所用的加密方式为MYSQL323,加密出来的HASH是16位的。MYSQL4.1包括之后的版本中,所用的加密方式为MYSQLSHA1,加密出来的HASH是40位的。

1、查询密码hash值
密码HASH会保存在mysq.user表里面,我们可以从这个表里面得到密码HASH:
mysql -uroot -pWelcome -Dmysql -e "select user,password,host from user;"

2、 mysqladmin 修改
Shell> mysqladmin -uroot -poldpassword password newpassword;

3、 grant修改
MySQL> create database db01;
MySQL> CREATE USER 'user01'@'localhost' IDENTIFIED BY 'Welcome';
MySQL> grant all privileges on db01.* to user01@"localhost" Identified by "Welcome";

4、 函数old_password()和password()

a)、old_password() Return the value of the pre-4.1 implementation of PASSWORD

MySQL5.5> select old_password('123456')from dual;
+--------------------+
| password('123456') |
+--------------------+
| 565491d704013245 |
+--------------------+
1 row in set (0.00 sec)

b)、PASSWORD() depends on the value of the old_passwords system variable:

#############################################################################
MySQL5.5> SET old_passwords = 1;

MySQL5.5> show variables like '%old%';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| old_passwords | ON |
+---------------+-------+
1 row in set (0.00 sec)

MySQL5.5> select password('123456')from dual;
+--------------------+
| password('123456') |
+--------------------+
| 565491d704013245 |
+--------------------+
1 row in set (0.00 sec)
#############################################################################
MySQL5.5> SET old_passwords = 0;

MySQL5.5> show variables like '%old%';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| old_passwords | OFF |
+---------------+-------+
1 row in set (0.00 sec)

MySQL5.5> select password('123456')from dual;
+-------------------------------------------+
| password('123456') |
+-------------------------------------------+
| *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
+-------------------------------------------+
1 row in set (0.00 sec)

5、 update user表
mysql -uroot -ppasswd -Dmysql -e "update user set password=password('新密码') where user='postfix';"

6、用set命令
mysql -uroot -ppasswd -Dmysql -e "SET PASSWORD FOR 'user01'@'localhost' = PASSWORD('Welcome');"

7、执行下面命令生效
mysql>flush privileges;
mysql>commit;

8、 other encryption functions
a) ENCRYPT(str[,salt])
Encryption performed by PASSWORD() is one-way (not reversible). It is not the same type of encryption as used for Unix passwords; for that,

use ENCRYPT().

b) md5() Calculates an MD5 128-bit checksum for the string.

c) sha1() Calculate an SHA-1 160-bit checksum

d) SHA2(str, hash_length) Calculates the SHA-2 family of hash functions (SHA-224, SHA-256, SHA-384, and SHA-512).

e) AES_ENCRYPT()/AES_DECRYPT(), DECODE()/ENCODE() , DES_DECRYPT()/DES_ENCRYPT() ,COMPRESS()/UNCOMPRESS()

参考网址:

http://dev.mysql.com/doc/refman/5.5/en/password-hashing.html
http://dev.mysql.com/doc/refman/5.5/en/encryption-functions.html

分类:数据库 | 标签: |

相关日志

评论被关闭!