MySQL – How to Generate Random Number

In MySQL, UUID() function returns Universal Unique Identifier that generates 36 characters long value which is 5 part hexadecimal numbers. If you want to generate random password, you can make use of this function which generate random number.

SELECT UUID() ;

Returns the string 85aeb064-8f73-11e5-85ef-02fcc4101968 (Note that this is random, when you execute you will get different value). As the total length is 36, you can make use of the result to get a random password with any length.

Suppose you want to generate 8 character length, you can generate it using

SELECT LEFT(UUID(),8) random_password ;

If you want to generate 10 character length, you can generate it using

SELECT RIGHT(UUID(),10) random_password ;

This way you can generate a random password. As UUID () returns the hexadecimal number with five parts separated by hyphen, your word will have numbers, alphabets and hyphen depends on the length you use.

MySQL - How to Generate Random Number uuid

There can be many ways of doing this, but this is the simplest one. Let me know what you think about this method. If you are using any other method please share the same in the comment sections. I will post it on this blog with due credit to you.

Reference: Pinal Dave (https://blog.sqlauthority.com)

MySQL, SQL Random
Previous Post
SQL SERVER – Install Error – The /UIMode setting cannot be used in conjunction with /Q or /QS
Next Post
SQL SERVER – How to Connect Using NT AUTHORITY \ SYSTEM Account?

Related Posts

Leave a Reply