intermediate6 min read

MySQL

Connecting MySQL

AI for Database supports MySQL 5.7+ and MariaDB 10.3+. This guide walks through creating a secure read-only user and configuring the connection.

Create a Read-Only User

sql
-- Create user with read-only access
CREATE USER 'aifordb_reader'@'%' IDENTIFIED BY 'a-strong-random-password';

-- Grant read access to a specific database
GRANT SELECT ON your_database.* TO 'aifordb_reader'@'%';

-- Apply changes
FLUSH PRIVILEGES;

Replace '%' with a specific IP address or CIDR range for tighter security.

Connection Settings

FieldExample
Hostmysql.example.com
Port3306
Databaseproduction
Usernameaifordb_reader
Password(your password)
SSL Moderequired

SSL Configuration

For cloud-hosted MySQL (AWS RDS, PlanetScale, etc.), SSL is typically enabled by default. Upload the CA bundle provided by your cloud provider in the Advanced section.

For self-managed MySQL, ensure require_secure_transport = ON in your MySQL configuration, and upload the server CA certificate.

SSH Tunnels

MySQL connections support SSH tunnels just like PostgreSQL. Enable the SSH Tunnel toggle and provide your bastion host credentials. This is the recommended approach for databases in private VPCs.

Character Sets

AI for Database uses utf8mb4 by default. If your database uses a different character set, you can specify it in the Advanced connection settings.

Troubleshooting

Access denied for user: Double check the username, password, and host restriction. Run SELECT user, host FROM mysql.user; to verify the user exists.

SSL connection error: If using RDS, download the combined CA bundle from AWS and upload it in the connection settings. Ensure the MySQL server has SSL enabled with SHOW VARIABLES LIKE '%ssl%';.

Too many connections: AI for Database uses a connection pool (default size 3). If your MySQL instance has a low max_connections limit, consider increasing it or reducing the pool size in the Advanced settings.