You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何将MySQL数据库student表的password字段批量转为MD5加密?

Fixing Your MD5 Password Encryption Query for MySQL

First off, let's break down why your original query failed: you're mixing SELECT (used to retrieve data) with SET (used to modify data), which isn't valid MySQL syntax. Plus, the @row variable reference doesn't make sense here since your data is already stored in the student table's password field.

Correct Query to Convert Plaintext Passwords to MD5

To update every row in your student table and replace plaintext passwords with their MD5 hashed versions, use an UPDATE statement instead:

UPDATE student
SET password = MD5(password);

Handling Extra Whitespace

If your plaintext passwords might have leading/trailing spaces (common when importing CSV files), add TRIM() to clean them up before hashing:

UPDATE student
SET password = MD5(TRIM(password));

Quick Notes

  • Backup First: Always make a backup of your student table before running mass updates like this—just in case something goes wrong.
  • MD5 Security: Keep in mind that MD5 is no longer considered secure for password storage. For better security, consider using MySQL's built-in PASSWORD() function or stronger hashing algorithms like SHA-256 (SHA2(password, 256)).

内容的提问来源于stack exchange,提问作者Alfred Joseph

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 07:28:53