> ## Documentation Index
> Fetch the complete documentation index at: https://docs.cloudthinker.io/llms.txt
> Use this file to discover all available pages before exploring further.

# MySQL

> Connect MySQL databases to CloudThinker for query analysis, performance monitoring, and database optimization

Connect your MySQL databases to enable [Tony](/guide/agents/tony) (Database Engineer) to analyze queries, optimize performance, and monitor database health.

***

## Supported Platforms

| Platform                     | Support            |
| ---------------------------- | ------------------ |
| **Self-hosted MySQL**        | 5.7, 8.0, 8.1+     |
| **MariaDB**                  | 10.x               |
| **AWS RDS MySQL**            | All versions       |
| **AWS Aurora MySQL**         | All versions       |
| **Google Cloud SQL**         | All MySQL versions |
| **Azure Database for MySQL** | Flexible Server    |

***

## Setup

<Steps>
  <Step title="Connect as Root">
    Connect to MySQL as root or admin user:

    ```bash theme={null}
    mysql -h your-host -u root -p
    ```
  </Step>

  <Step title="Create Read-Only User">
    Create the CloudThinker user:

    ```sql theme={null}
    CREATE USER 'cloudthinker_readonly'@'%' IDENTIFIED BY 'your-secure-password';
    ```
  </Step>

  <Step title="Grant Read Permissions">
    Grant SELECT and monitoring privileges:

    ```sql theme={null}
    GRANT SELECT ON *.* TO 'cloudthinker_readonly'@'%';
    GRANT SHOW DATABASES ON *.* TO 'cloudthinker_readonly'@'%';
    GRANT PROCESS ON *.* TO 'cloudthinker_readonly'@'%';
    ```
  </Step>

  <Step title="Grant Performance Schema Access">
    Required for query analysis:

    ```sql theme={null}
    GRANT SELECT ON performance_schema.* TO 'cloudthinker_readonly'@'%';
    ```
  </Step>

  <Step title="Apply Changes">
    Flush privileges to apply changes:

    ```sql theme={null}
    FLUSH PRIVILEGES;
    ```
  </Step>

  <Step title="Enable Performance Schema">
    Verify Performance Schema is enabled:

    ```sql theme={null}
    SHOW VARIABLES LIKE 'performance_schema';
    -- Should return: ON
    ```

    If disabled, add to `my.cnf`:

    ```ini theme={null}
    [mysqld]
    performance_schema = ON
    ```
  </Step>

  <Step title="Configure Network Access">
    Ensure CloudThinker can reach your database:

    * Add CloudThinker IPs to security group / firewall
    * For RDS: Enable public access or use VPC peering
  </Step>

  <Step title="Add Connection in CloudThinker">
    Navigate to **Connections → MySQL** and enter:

    * Host
    * Port (default: 3306)
    * Database name
    * Username: `cloudthinker_readonly`
    * Password
    * SSL (recommended: enabled)
  </Step>
</Steps>

***

## Connection String Format

```
mysql://cloudthinker_readonly:your-secure-password@your-host:3306/database-name
```

**Example:**

```
mysql://cloudthinker_readonly:mypassword123@mysql.example.com:3306/production
```

***

## Required Permissions

### Minimum

```sql theme={null}
GRANT SELECT ON your_database.* TO 'cloudthinker_readonly'@'%';
GRANT PROCESS ON *.* TO 'cloudthinker_readonly'@'%';
```

### Recommended (Full Analysis)

```sql theme={null}
-- All of the above, plus:
GRANT SELECT ON performance_schema.* TO 'cloudthinker_readonly'@'%';
GRANT SELECT ON mysql.* TO 'cloudthinker_readonly'@'%';
GRANT REPLICATION CLIENT ON *.* TO 'cloudthinker_readonly'@'%';
```

***

## Agent Capabilities

Once connected, [Tony](/guide/agents/tony) can:

| Capability                 | Description                                                      |
| -------------------------- | ---------------------------------------------------------------- |
| **Query Analysis**         | Identify slow queries from slow query log and Performance Schema |
| **Index Recommendations**  | Find missing indexes, identify redundant indexes                 |
| **Performance Metrics**    | Monitor connections, buffer pool, query cache                    |
| **Table Statistics**       | Analyze table sizes, fragmentation, engine status                |
| **Replication Monitoring** | Check slave status, lag, errors                                  |

### Example Prompts

```bash theme={null}
@tony analyze slow queries on production MySQL
@tony #dashboard database performance metrics
@tony recommend index optimizations for high-frequency queries
@tony check replication status on the read replica
```

***

## Connection Options

| Option                 | Description                        | Default |
| ---------------------- | ---------------------------------- | ------- |
| **SSL**                | Enable SSL/TLS encryption          | Enabled |
| **Connection Timeout** | Seconds to wait for connection     | 10      |
| **Read Timeout**       | Max time to wait for query results | 30      |

***

## Troubleshooting

<Accordion title="Connection refused">
  * Verify host and port are correct
  * Check security group / firewall allows CloudThinker IPs
  * For RDS: Ensure "Publicly accessible" is enabled or use VPC peering
  * Confirm MySQL is listening on the correct interface (`bind-address`)
</Accordion>

<Accordion title="Access denied">
  * Verify username and password are correct
  * Check user has correct host specification (`'user'@'%'` vs `'user'@'localhost'`)
  * Ensure GRANT statements were followed by FLUSH PRIVILEGES
</Accordion>

<Accordion title="Performance Schema disabled">
  * Check with: `SHOW VARIABLES LIKE 'performance_schema';`
  * Enable in `my.cnf` and restart MySQL
  * For RDS: Modify parameter group and reboot
</Accordion>

<Accordion title="Missing slow query data">
  * Enable slow query log: `SET GLOBAL slow_query_log = 'ON';`
  * Set threshold: `SET GLOBAL long_query_time = 1;`
  * For RDS: Modify parameter group
</Accordion>

***

## Security Best Practices

* **Strong passwords** - Use complex, unique passwords
* **SSL encryption** - Always enable SSL for connections
* **Network restrictions** - Limit access to CloudThinker IPs only
* **Minimal permissions** - Grant only SELECT, never write access
* **Credential rotation** - Rotate passwords every 90 days

***

## Related

<CardGroup cols={2}>
  <Card title="Tony Agent" icon="database" href="/guide/agents/tony">
    Database-focused optimization agent
  </Card>

  <Card title="PostgreSQL Connection" icon="https://mintcdn.com/cloudthinker/aLd-ttc-SCW-aFky/images/icons/postgresql.svg?fit=max&auto=format&n=aLd-ttc-SCW-aFky&q=85&s=8bb2ac033d0a2ccbef51154a76e1e819" href="/guide/connections/postgresql" width="24" height="24" data-path="images/icons/postgresql.svg">
    Similar setup for PostgreSQL databases
  </Card>
</CardGroup>
