ToolJet can connect to MySQL databases to read and write data.
<divstyle={{paddingTop:'24px'}}>
## Connection
To establish a connection with the MySQL data source, you can either click on the **+ Add new Data source** button located on the query panel or navigate to the **[Data Sources](/docs/data-sources/overview)** page through the ToolJet dashboard.
**ToolJet requires the following to connect to your MySQL database:**
- **Username**
- **Password**
- **Database Name**
- **Connection Type**
If you are using **Hostname** as the connection type, you will need to provide the following information:
- **Host/IP**
- **Port**
- **SSL**
- **SSL Certificate**:
- **CA Certificate**
- **Self-signed Certificate**
- **None**
If you are using **Socket** as the connection type, you will need to provide the following information:
ToolJet allows you to configure the Host and Database directly within the query instead of setting them in the data source configuration.
This is particularly useful in multi-tenant applications, where the same ToolJet application needs to connect to different databases based on the active tenant. Instead of creating multiple data sources for each tenant, you can define the host and database dynamically within the query.
To enable this feature, turn on the **Allow dynamic connection parameters** toggle on the data source configuration page.
Once you enable **Allow dynamic connection parameters**, you can write custom logic directly inside the query editor to determine which Host and Database to use based on the current logged-in user.
Please make sure the **Host/IP** of the database is accessible from your VPC if you have self-hosted ToolJet. If you are using ToolJet cloud, please **whitelist** our IP.
ToolJet offers support for parameterized SQL queries, which enhance security by preventing SQL injection and allow for dynamic query construction. To implement parameterized queries:
1. Use `:parameter_name` as placeholders in your SQL query where you want to insert parameters.
2. In the **Parameters** section below the query editor, add key-value pairs for each parameter.
3. The keys should match the parameter names used in the query (without the colon).
4. The values can be static values or dynamic values using the `{{ }}` notation.
You can set the timeout duration for SQL queries by adding the `PLUGINS_SQL_DB_STATEMENT_TIMEOUT` variable to the environment configuration file. By default, it is set to 120,000 ms.
MySQL offers dynamic functions and system variables that provide real-time information about the current database, user session, connection, and server environment. These can help you write queries that automatically adapt to different environments without hardcoding values.
| Function / Variable | Description | Example Output |