Skip navigation.
Sponsors
Recent comments
Generate random string in MySQL

Generate random string in MySQL

10
Jul
2008

Have you ever wanted to generate a random string in MySQL, say for assigning a random password to a list of users? Well here is a usefull tip!

SELECT SUBSTRING(MD5(RAND()) FROM 1 FOR 6) AS password

This creates a 6 charatcer (easy to change, as you can see) string where the characters are from the MD5 command (and therefore in the range a-z and 0-9).

Excellent tip - this would

Excellent tip - this would allow you to have a function for generating md5 keys for sessions instead of perl code... put it all in the db.

It'd be nice if you asked before taking stuff from my site. Contact me at webmaster [at] thingy - ma - jig . co . uk

This site was based on the Cobalt 2.0 Theme for phpBB written by Jakob Persson

Search
Weblinks

Add to Technorati Favorites

TGC Webring

CMS Drupal Showcase

Feedburner for ThingyMaJig

View Nicholas Thompson's profile on LinkedIn

IconBuffet

Twitter