MySQL Overview
TheMYSQL route stores MQTT messages in MySQL databases. It supports SSL connections, parameterized queries, and automatic reconnection for reliable data persistence.
MySQL is ideal for web applications and general-purpose data storage. Its wide ecosystem support makes it a reliable choice for most IoT data persistence needs.
Basic Syntax
Connection Configuration
SQL_CONFIG Parameters
MySQL server hostname or IP address.
Target database name.
Database username.
Database password.
Event Configuration
EVENT Parameters
MQTT topic pattern that triggers the INSERT. Supports wildcards.
SQL INSERT statement with placeholders for dynamic values.
Optional Settings
Optional Settings
MQTT topic to publish query result status.
Query Placeholders
Writing Data
- Basic Sensor Storage
- With SSL
- Multiple Events
- UPSERT
- UPDATE
- DELETE
Store sensor readings with timestamps:
Alternative: STORE IN with Models — Instead of writing EVENT queries, you can bind a model directly to this route. Every See Data Storage Overview for the full STORE IN workflow.
PUBLISH MODEL call automatically inserts a row — no query needed:Reading Data
EVENTs also support SELECT queries to read data back from the database. Publish a message to the event’sSOURCE_TOPIC, and the query result is published to DESTINATION_TOPIC:
db/result/latest, where your actions or external clients can consume it.
Timed Polling
EVENTs can also run SELECT queries on a fixed schedule usingWITH EVERY:
Table Schema Examples
Troubleshooting
Connection Refused
Connection Refused
- Verify SERVER and PORT are correct
- Check MySQL is running and accepting connections
- Verify firewall allows connections on port 3306
- Check
bind-addressin MySQL configuration
Authentication Failed
Authentication Failed
- Verify USERNAME and PASSWORD are correct
- Check user has permissions on the DATABASE
- Verify user can connect from your host
Query Syntax Errors
Query Syntax Errors
- Check placeholder names match topic structure
- Verify table and column names exist
- Test query manually in MySQL client first
Next Steps
Data Storage Routes Overview
Compare all storage options.
MariaDB Route
Configure MariaDB storage (MySQL-compatible).

