content/flux/v0/write-data/sql/mariadb.md
To write data to MariaDB with Flux:
Import the sql package.
Pipe-forward data into sql.to() and provide
the following parameters:
Exec (default is 10000)import "sql"
data
|> sql.to(
driverName: "mysql",
dataSourceName: "user:password@tcp(localhost:3306)/db",
query: "SELECT * FROM example_table",
)
The mysql driver uses the following data source name (DSN) syntax (also known as a connection string):
username:password@tcp(localhost:3306)/dbname?param=value
sql.to() converts Flux data types to MariaDB data types.
| Flux data type | MariaDB data type |
|---|---|
| float | FLOAT |
| int | BIGINT |
| uint | BIGINT |
| string | TEXT(16383) |
| bool | BOOL (TINYINT) |
| time | DATETIME |
{{% note %}}
BOOL is a synonym supplied by MariaDB for convenience.
MariaDB stores BOOL values as TINYINT types so looking at the schema shows the
column type as TINYINT.
{{% /note %}}