Have you ever wanted to generate a random string in MySQL, say for assigning a random password to a list of users?
SELECT SUBSTRING(MD5(RAND()) FROM 1 FOR 6) AS passwordString
This generates a 6 character string where the characters are taken randomly from the MD5 command (and therefore in the range a-z and 0-9).
Enjoy………
Great tips.
Quick question, is it possible the sql will generate same string?
Hi,
Using the given example, it will take combination of 6 diff. random characters and/or numbers.
Still if to avoid the generation of same string, we can increase the no. of characters depending upon the requirement. that can reduce the chances of generating same string again.
thanks , this helped me 🙂