# MySQL

Connect RootCause.ai to your MySQL database to import tables or run custom queries.

***

### Prerequisites

Before connecting, ensure you have:

* MySQL database hostname or IP address
* Port number (default: 3306)
* Database name
* Username and password with read access to the tables you want to import
* Network access from RootCause.ai to your database (firewall rules, VPN, etc.)

***

### Setting Up the Connection

1. Navigate to **Data** → **Datasets** in your workspace
2. Click **New Connection** and select **MySQL**
3. Enter your connection details:

| Field      | Description                    | Example          |
| ---------- | ------------------------------ | ---------------- |
| Host       | Database server hostname or IP | `db.example.com` |
| Port       | MySQL port                     | `3306`           |
| Database   | Database name                  | `analytics`      |
| Username   | Database user                  | `readonly_user`  |
| Password   | User password                  | `••••••••`       |
| Enable SSL | Use encrypted connection       | ✓ Recommended    |

4. Click **Test Connection** to verify your credentials
5. Click **Save** to create the connector

***

### Importing Data

Once your connector is saved, you can import data in two ways:

**Import a Table**

Select "Table" as the import type and enter the table name. RootCause.ai will import all columns and rows from that table.

**Custom SQL Query**

Select "Custom Query" to write your own SQL. This is useful for:

* Joining multiple tables
* Filtering rows before import
* Selecting specific columns
* Aggregating data

Example:

```sql
SELECT 
  customer_id,
  order_date,
  total_amount
FROM orders
WHERE order_date >= '2024-01-01'
```

***

### What Happens When You Import

1. RootCause.ai executes your query against the database
2. Results are stored securely in your workspace's data lake
3. Schema is automatically detected (column names, data types)
4. A preview is generated so you can verify the data

The imported dataset becomes available for use in [Data Views](https://docs.rootcause.ai/user-guide/data-management/data-views) and [Ontology](https://docs.rootcause.ai/core-technologies/ontology) mapping.

***

### Live Data Sync

You can configure automatic syncing to keep your dataset current:

* **Manual** – Only sync when you click "Sync Now"
* **Hourly** – Refresh every hour
* **Daily** – Refresh once per day
* **Weekly** – Refresh once per week

When a sync runs, the entire dataset is replaced with fresh data from the source.

***

### Security Recommendations

* Use a dedicated read-only database user for RootCause.ai
* Enable SSL for encrypted connections
* Restrict the user's access to only the tables needed
* Use IP allowlisting if your database supports it

***

### Troubleshooting

**Connection timeout**

* Verify the hostname and port are correct
* Check that your firewall allows connections from RootCause.ai
* Ensure the database is running and accepting connections

**Authentication failed**

* Verify username and password
* Check that the user has the necessary privileges
* For MySQL 8+, ensure the user uses a compatible authentication method

**Permission denied on table**

* Grant SELECT permission to the user on the required tables
* Run: `GRANT SELECT ON database.table TO 'user'@'host';`
