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

The TO_BASE64 SQL Function in MySQL and MariaDB - Encode to Base-64

TO_BASE64Syntax:TO_BASE64(String)
Return value:CHAR
Function type:Encryption & Compression
Function Description

The TO_BASE64() function encodes the argument "String" into its base-64 encoded form and returns the result with the current character set and collation of the connection.

The output consists of groups of four characters, with 3 data bytes being encoded in 4 characters.

If the last group is not complete, it will be padded to 4 characters with "="-characters.

To split long output, a line break is inserted after every 76 characters.

The decode recognizes and ignores newlines, carriage returns, tabs, and spaces.


Numeric values ​​are interpreted as strings.

If the value of "String" is NULL, the TO_BASE64() function returns NULL.


The reverse function of TO_BASE64() is FROM_BASE64() for decoding base-64 strings.

SQL Examples for the TO_BASE64 function

 1
 2
 3
 4
 5
 6
 7
 8
 9

select to_base64('Test');
select to_base64(1234);
select to_base64('123456');
select to_base64(repeat('Test',60));

select to_base64('');
select to_base64(null);

to_base64('Test')
varchar(8) BINARY
VGVzdA==
to_base64(1234)
varchar(8) BINARY
MTIzNA==
to_base64('123456')
varchar(8) BINARY
MTIzNDU2
to_base64(repeat('Test',60))
varchar(324) BINARY
VGVzdFRlc3RUZXN0VGVzdFRlc3RUZXN0VGVzdFRlc3RUZXN0VGVzdFRlc3RUZXN0VGVzdFRlc3RU
ZXN0VGVzdFRlc3RUZXN0VGVzdFRlc3RUZXN0VGVzdFRlc3RUZXN0VGVzdFRlc3RUZXN0VGVzdFRl
c3RUZXN0VGVzdFRlc3RUZXN0VGVzdFRlc3RUZXN0VGVzdFRlc3RUZXN0VGVzdFRlc3RUZXN0VGVz
dFRlc3RUZXN0VGVzdFRlc3RUZXN0VGVzdFRlc3RUZXN0VGVzdFRlc3RUZXN0VGVzdFRlc3RUZXN0
VGVzdFRlc3RUZXN0
to_base64('')
varchar(0) BINARY
 
to_base64(null)
varchar(0) BINARY
NULL
The examples were created with the MyWAY SQL manager: Download

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

In MySQL and MariaDB the TO_BASE64() function can be used to encode a string or binary data into a Base64 representation. The function takes a string or binary value as input and returns the Base64-encoded representation of that value. Binary data such as images or files can also be encoded. Base64 encoding can be used when binary data needs to be represented in a text format, for example when transmitting binary data over text-based protocols such as HTTP, or when storing binary data in text-based fields in databases.

By using TO_BASE64() together with FROM_BASE64() data can be easily encoded and decoded in Base64 format.
TIMESTAMPTIMESTAMPADDTIMESTAMPDIFFTO_BASE64TO_DAYSTO_SECONDSTRIM

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

RANDOM_BYTESRANDOM_BYTES(Length)
More about RANDOM_BYTES Function

SHASHA(String)
More about SHA Function

SHA1SHA1(String)
More about SHA1 Function

SHA2SHA2(String, Length)
More about SHA2 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 TO_BASE64 SQL function: mysql.com and mariadb.com
Updated: 2023-09-24ImprintContactTerms & conditionsPrivacy & CookiesUpdatesSitemapFacebookLinkedinTwitterStatistics©2020-2024 Heino Cunze-Fischer