This appendix details the implementation of column-level encryption within MariaDB databases using its built-in encryption functions like AES_ENCRYPT and AES_DECRYPT. When paired with Transparent Data Protection (TDP), this approach enables granular security controls where specific database directories can be selectively encrypted. By combining these complementary encryption methodologies, you can establish a multi-layered defense strategy that protects sensitive data both at the application level and within the physical storage architecture.Documentation Index
Fetch the complete documentation index at: https://docs.futurex.com/llms.txt
Use this file to discover all available pages before exploring further.
Connect to MariaDB
Connect to MariaDB by using one of the following techniques:- Use HeidiSQL.
- Use the command line.
Use HeidiSQL (GUI)
Perform the following steps to connect to MariaDB by using HeidiSQL (GUI):Enter the following Connection settings:
- Network type: Select MariaDB or MySQL (TCP/IP).
- Hostname / IP: Enter your server IP address or hostname (use
127.0.0.1orlocalhostfor local connections). - User: Enter your MariaDB username (such as root or a specific user).
- Password: Enter your password.
- Port:
3306(default for MariaDB/MySQL).
Use the command line
Perform the following steps to connect to MariaDB by using the command line:Create a new database
Create a new database by using one of the following techniques:- Use HeidiSQL.
- Use the command line.
Use HeidiSQL
Use the command line
Create a sample table and apply AES_ENCRYPT at the column level
The following SQL query creates a table and inserts data, encrypting the ssn column by using AES_ENCRYPT.AES_ENCRYPT returns a binary string (VARBINARY or BLOB). We define the ssn column accordingly.
View unencrypted data
To decrypt the data when querying, use the AES_DECRYPT function. You likely need to CAST the result back to a readable character type (like CHAR) by using the following command:View column-level encrypted data
To see the raw encrypted data stored in the table (which appears as binary or unreadable characters in most clients), use the following command to select the column directly:View column-level encrypted data in hexadecimal format
To view the encrypted binary data as a more readable hexadecimal string, use the following HEX() function:Find the physical DB files location
MariaDB typically stores each database in a subdirectory within its main data directory. This section explores locating the data directory and database folder.Find the MariaDB data directory
Run the following SQL query to find the directory:Sql
C:\Program Files\MariaDB X.Y\data\).
Locate the database folder
- Go to the
datadirpath on your server file system. - That directory contains a folder named after your database (such as
TestDB). This folder contains the physical files for your tables, such as.frm,.ibdfiles if using InnoDB.
Summary of the Symmetric Key used for an encryption operation
- Function:
AES_ENCRYPT/AES_DECRYPTin MariaDB. - Algorithm: Uses the Advanced Encryption Standard (AES). By default, it uses AES-128. You can configure the block encryption mode by using the block_encryption_mode system variable (the default often depends on the MariaDB version, but it might be
aes-128-ecb). - Key: You directly provide the
key_str(passphrase) to the functions. MariaDB uses this string to perform the encryption or decryption. - Key Management: Crucially, you are responsible for managing this
key_str. MariaDB does not store it in relation to these functions. In real applications, avoid hardcoding keys directly in SQL or application code. Store them securely (such as in a secrets manager, environment variables, or a secure configuration file) and pass them to the application logic that constructs the SQL query.
Encryption example
We recommend you handle key loading in your application code:- Your application reads the encryption key from the text file, such as
C:\MariaDBKeys\DEK.txt. - The application then passes this key as a parameter or variable when constructing the SQL query that uses
AES_ENCRYPTorAES_DECRYPT.

