Skip to main content

MariaDB Overview

The MARIADB route stores MQTT messages in MariaDB databases. MariaDB is a MySQL-compatible database with enhanced features and performance optimizations.
MariaDB offers drop-in MySQL compatibility with additional features like improved replication and storage engines. Use the same configuration as MySQL with the MARIADB route type.

Basic Syntax

DEFINE ROUTE SensorDB WITH TYPE MARIADB
    ADD SQL_CONFIG
        WITH SERVER "mariadb.example.com"
        WITH PORT '3306'
        WITH DATABASE "iot_data"
        WITH USERNAME "iot_user"
        WITH PASSWORD "secure_password"
    ADD EVENT StoreSensorReading
        WITH SOURCE_TOPIC "sensors/+/reading"
        WITH QUERY "INSERT INTO readings (ts, sensor_id, value) VALUES (NOW(), '{sensor_id}', '{value.json}')"

Connection Configuration

SQL_CONFIG Parameters

SERVER
string
required
MariaDB server hostname or IP address.
PORT
integer
MariaDB port. Default: 3306.
DATABASE
string
required
Target database name.
USERNAME
string
required
Database username.
PASSWORD
string
required
Database password.
USE_SSL
boolean
Enable SSL connection. Default: false.

Complete Examples

Store sensor data in MariaDB:
DEFINE ROUTE SensorStorage WITH TYPE MARIADB
    ADD SQL_CONFIG
        WITH SERVER "mariadb.example.com"
        WITH PORT '3306'
        WITH DATABASE "iot_data"
        WITH USERNAME "iot_user"
        WITH PASSWORD "secure_password"
    ADD EVENT StoreReading
        WITH SOURCE_TOPIC "sensors/#"
        WITH QUERY "INSERT INTO sensor_data (timestamp, topic, payload) VALUES (NOW(), '{source_topic}', '{value.json}')"

Troubleshooting

  • Verify SERVER and PORT are correct
  • Check MariaDB is running and accepting connections
  • Verify firewall allows connections on port 3306
  • Verify USERNAME and PASSWORD are correct
  • Check user has permissions on the DATABASE
  • Verify user can connect from your host

Next Steps