©SQL :: Manager
HomeProgram InformationTechnical detailsFree downloadDonate for a cup of coffee
myway SQL Manager for MySQL and MariaDB, Download on Uptodown
SQL functionMySQLMariaDB

The RANDOM_BYTES SQL Function in MySQL and MariaDB - Random bytes

RANDOM_BYTESSyntax:RANDOM_BYTES(Length)
Return value:BINARY
Function type:Encryption & Compression
Function Description

The RANDOM_BYTES() function generates a binary string of random bytes with the number "Length".

RANDOM_BYTES() uses the SSL library's random number generator.

An error occurs if the "Length" is not within the range from 1 to 1024 and is not NULL.

If the value of "Length" is NULL, the function returns NULL.


In MariaDB, the function is only available from version 10.10.

SQL Examples for the RANDOM_BYTES function

 1
 2
 3
 4
 5
 6
 7

SELECT hex(RANDOM_BYTES(1));
SELECT hex(RANDOM_BYTES(5));
SELECT hex(RANDOM_BYTES(15));

SELECT RANDOM_BYTES(null);

hex(RANDOM_BYTES(1))
varchar(2048) BINARY
FD
hex(RANDOM_BYTES(5))
varchar(2048) BINARY
BBF65E7C99
hex(RANDOM_BYTES(15))
varchar(2048) BINARY
5F4A4032A89FE6F38D58DEF23D20D5
RANDOM_BYTES(null)
varchar(1024) BINARY
NULL
The examples were created with the MyWAY SQL manager: Download

How to use the RANDOM_BYTES() function in MySQL and MariaDB databases

The RANDOM_BYTES() function in MySQL and MariaDB is used to generate a specified number of random bytes. The function takes an integer parameter representing the number of bytes to generate and returns a binary string of random bytes that can be used in applications where random data needs to be generated, for example for random encryption keys, when creating random salts for password hashing, or to generate random tokens for session management or authentication purposes.

The function is available from MySQL version 8.0.13 and MariaDB version 10.10 or higher.
QUOTERADIANSRANDRANDOM_BYTESREGEXPREGEXP_INSTRREGEXP_LIKE

Further MySQL und MariaDB SQL Encryption & Compression

AES_DECRYPTAES_DECRYPT(String, Key)
More about AES_DECRYPT Function

AES_ENCRYPTAES_ENCRYPT(String, Key)
More about AES_ENCRYPT Function

COMPRESSCOMPRESS(String)
More about COMPRESS Function

DECODEDECODE(Binary string, Password)
More about DECODE Function

DES_DECRYPTDES_DECRYPT(Binary string [, Key])
More about DES_DECRYPT Function

DES_ENCRYPTDES_ENCRYPT(String [, Key])
More about DES_ENCRYPT Function

ENCODEENCODE(String, Password)
More about ENCODE Function

ENCRYPTENCRYPT(String [, Salt])
More about ENCRYPT Function

FROM_BASE64FROM_BASE64(String)
More about FROM_BASE64 Function

MD5MD5(String)
More about MD5 Function

OLD_PASSWORDOLD_PASSWORD(String)
More about OLD_PASSWORD Function

PASSWORDPASSWORD(String)
More about PASSWORD Function

SHASHA(String)
More about SHA Function

SHA1SHA1(String)
More about SHA1 Function

SHA2SHA2(String, Length)
More about SHA2 Function

TO_BASE64TO_BASE64(String)
More about TO_BASE64 Function

UNCOMPRESSUNCOMPRESS(Binary string)
More about UNCOMPRESS Function

Numeric functionsString functionsRegular ExpressionsDate and Time functions
Comparison functionsEncryption & CompressionConversion functionsNULL functions
Aggregate functionsWindow functionsJSON functionsGeometric functions
Sequence functionsInformation functionsDynamic ColumnsMiscellaneous functions
More information about the RANDOM_BYTES SQL function: mysql.com and mariadb.com
Updated: 2023-09-24ImprintContactTerms & conditionsPrivacy & CookiesUpdatesSitemapFacebookLinkedinTwitterStatistics©2020-2024 Heino Cunze-Fischer