doumibi6899 2013-12-10 03:02
浏览 40

将Mysql旧密码升级到新版本[重复]

This question already has an answer here:

This probably has been asked before. Some passwords for the users are stored in 16 bit format. Mysql has been upgraded to 5.5, but the passwords in the table remained in a 16 bit format.

A way to tell what password scheme your MySQL is using is to run this query below, it will list each user’s password length (16 or 41):

mysql> SELECT `User`, `Host`, Length(`Password`) FROM mysql.user;
+—————-+—————–+——————–+
| User | Host | Length(`Password`) |
+—————-+—————–+——————–+
| root | localhost | 16 |
| mary | 20.20.3.2 | 16 |
| fred | localhost | 16 |
| sally | 64.56.139.194 | 16 |
| fschmidt | 64.56.139.194 | 16 |
…

To change the user to having the exact same password but stored in the newer longer format, we can do this:

mysql> SET SESSION old_passwords=FALSE;
mysql> SET PASSWORD FOR ‘visitlogger’@’64.55.129.%’=PASSWORD(‘ ‘);
mysql> flush privileges;

Now we can verify the changes:

mysql> SELECT `User`, `Host`, Length(`Password`) FROM mysql.user;
+—————-+—————–+——————–+
| User | Host | Length(`Password`) |
+—————-+—————–+——————–+
| root | localhost | 41 |
| mary | 20.20.3.2 | 41 |
| fred | localhost | 41 |
| sally | 64.56.139.194 | 41 |
| fschmidt | 64.56.139.194 | 41 |
+—————-+—————–+——————–+

Can anyone help me figuring out a way to make this changes automatically. It will be a pain to do this manually for all my users. Thank you!

</div>
  • 写回答

1条回答 默认 最新

  • dsf12313 2013-12-10 03:22
    关注

    If you want to set up password to some predefined value to all users that have their password in old format, without issuing SET PASSWORD for each one of them, you can do

    SET SESSION old_passwords=FALSE;
    UPDATE mysql.user 
       SET password = PASSWORD('<some predefined value>')
     WHERE LENGTH(password) = 16;
    FLUSH PRIVILEGES;
    

    Note: before doing any updates make sure you a have solid backup. Just in case.

    评论

报告相同问题?

悬赏问题

  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作