Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Convert Column to MD(5)

Status
Not open for further replies.

jsnull

IS-IT--Management
Feb 19, 2002
99
US
I have column I'd like to make MD(5) from MySQL Admin ... so an sql something like

"UPDATE `thistable` SET `column1` = md5(`column1`)"

is what I am looking for. However this syntax fails. Suggestions?

Jim Null
[afro]
 
You're trying to change the column name:

ALTER TABLE `thistable` CHANGE COLUMN `column1` `md5`;

If you're trying to set the value of column1 to md5, then:

UPDATE `thistable` SET `thistable`.`column1` = `md5`
WHERE `thistable`.`column1` = `currentvalue`
 
Jim, when you say this syntax fails you have not told us the exact error message produced by the failure. Usually, but not always, the error message provides a good indication of what is wrong.

It would also help to give us a description of the table. What kind of column is column1? An MD5 checksum consists of 32 hexadecimal digits. Is the data type of column1 suitable to receive 32 hexadecimal digits?

Incidentally, there is no need to put tick marks around names such as thistable or column1 unless the names contain spaces. I hope that these are not the names you are using in your real application ....

Andrew
Hampshire, UK
 
Howdies ... I basically have a varchar column, lets say it is named myname. I want to change the contents of this column to md5.

Jim Null
[afro]
 
your code in the first table is correct, though I would use SHA1 instead of MD5 as MD5 has been hacked.
 
Everyone ... thank you for your feedback. With the details each of you have provided I altered the code to this:

UPDATE thistable SET `column1` = md5(`column1`)

and it worked perfectly. I removed the ` from around the table name.

Jim Null
[afro]
 
you never need to use the backticks unless you are using a reserved word as the name of a database, table or column. in that case you are always better to rename it rather than have to resort to using the backtick which is non-standard.

any reason you are set on using MD5 when it isn't secure?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top