MySQL

View as Markdown

The MySQL connector turns approved relational rows into searchable documents. It supports two indexing modes:

  • Automatic discovery reads accessible base tables in the selected database, lets administrators select tables and columns, and maps rows into documents.
  • Custom SQL runs a controlled SELECT or WITH query and maps returned columns into document ID, title, searchable content, metadata, and update time.

Use a dedicated read-only account and expose only curated tables or views. Do not connect a broad production account to a database that contains unapproved personal data, credentials, tokens, or operational secrets.

What You Need

ItemRequirement
Network routeAIvis workers must be able to reach the MySQL host and port. Use private networking, a database proxy, or an allowlisted egress IP.
CredentialA dedicated MySQL account with SELECT only on approved tables or views.
Data scopePrefer sanitized views for sensitive tables, joins, aggregates, or field renaming.
Stable identityUse a primary key, a non-null unique key, or a stable id_column in Custom SQL.
Update fieldPrefer a datetime or timestamp column such as updated_at for incremental sync.
Transport securityThe current MySQL credential form exposes host, port, database, username, and password only. If your database requires client TLS options, place the database behind an approved private endpoint or proxy before enforcing that policy for this connector.

Create a Read-Only MySQL Account

Run grants from a database administrator account. Adjust host pattern, database, table, and view names to match your environment.

1CREATE USER 'aivis_reader'@'10.0.%'
2 IDENTIFIED BY '<generated-password>'
3 WITH MAX_USER_CONNECTIONS 3;
4
5GRANT SELECT ON knowledge.product_catalog_view TO 'aivis_reader'@'10.0.%';
6GRANT SELECT ON knowledge.faq_article_view TO 'aivis_reader'@'10.0.%';
7
8SHOW GRANTS FOR 'aivis_reader'@'10.0.%';

MySQL supports account-level TLS requirements such as REQUIRE SSL. Enable them for this account only when your AIvis deployment path provides compatible MySQL TLS handling, for example through an approved private database proxy.

Create views when the source tables contain sensitive columns:

1CREATE VIEW knowledge.product_catalog_view AS
2SELECT
3 id,
4 name,
5 status,
6 public_summary,
7 category,
8 updated_at
9FROM product_catalog
10WHERE searchable = 1;
11
12GRANT SELECT ON knowledge.product_catalog_view TO 'aivis_reader'@'10.0.%';

Use database-level grants only for a database that is already curated for AIvis indexing:

1GRANT SELECT ON aivis_public.* TO 'aivis_reader'@'10.0.%';

Create the Credential

AIvis FieldRecommended ValueNotes
HostMySQL host name or private endpoint.Do not include protocol prefixes such as mysql://.
Port3306 unless your deployment uses a custom port.The UI defaults to 3306.
DatabaseThe database containing approved tables or views.Automatic discovery reads base tables in this database.
UsernameDedicated read-only account, such as aivis_reader.Avoid root, owner, migration, or application writer accounts.
PasswordGenerated password for the read-only account.Rotate it through your normal credential process.

The connector uses utf8mb4 when reading MySQL rows and sets a 10-second connection timeout.

Choose an Indexing Mode

ModeUse WhenBoundary
Automatic discoveryYou want AIvis to discover accessible base tables in one database and let an admin select tables and fields.It discovers base tables, not arbitrary joins or views. Use Custom SQL for views, joins, aggregates, or renamed fields.
Custom SQLYou need a curated view, join, filter, projection, or stable row shape.The query must be a single SELECT or WITH statement and return one row per document.

Automatic Discovery

Automatic discovery reads accessible base tables in the selected database and ignores MySQL system schemas such as information_schema, mysql, performance_schema, and sys.

In the schema tree:

  • Select only tables and fields that are approved for indexing.
  • Binary, geometry, and blob-like columns are not indexed.
  • AIvis uses primary keys first, then non-null unique indexes, then a row hash when no stable key exists.
  • Tables without a stable key can create new document IDs when selected values change; prefer adding a primary key or using Custom SQL with an explicit ID.
  • The default title field is inferred from columns such as title, name, subject, or label; you can override it in table settings.
  • The update field is inferred from datetime columns such as updated_at, updated, modified_at, modified, or last_modified; no update field means the table requires full scans.

Custom SQL Requirements

The connector wraps your query as a subquery and validates returned columns. Keep the SQL read-only and deterministic.

FieldRequirement
SQL QueryA single SELECT or WITH query. Do not include a trailing semicolon or multiple statements.
ID ColumnA non-empty unique value per row. Cast compound keys to text when needed.
Title ColumnA human-readable title used as the document name.
Content ColumnsOne or more columns whose values become searchable document text.
Metadata ColumnsOptional fields stored as metadata for filtering or debugging.
Updated At ColumnOptional datetime or timestamp column used to poll only rows updated in each sync window.
Batch SizeNumber of rows fetched per batch. The UI default is 16; increase only after testing query cost.

Example:

1SELECT
2 CAST(p.id AS CHAR) AS doc_id,
3 p.name AS title,
4 CONCAT_WS(
5 '\n',
6 CONCAT('Status: ', p.status),
7 CONCAT('Category: ', p.category),
8 CONCAT('Summary: ', p.public_summary)
9 ) AS body,
10 p.category,
11 p.updated_at
12FROM knowledge.product_catalog_view AS p
13WHERE p.searchable = 1

For this query, set:

AIvis FieldValue
ID Columndoc_id
Title Columntitle
Content Columnsbody
Metadata Columnscategory
Updated At Columnupdated_at

Production Safety

The connector opens MySQL reads in a read-only transaction and sets max_execution_time during reads. That protects AIvis from writing data, but it does not replace database-side controls.

Before production:

  • Use a replica, analytics database, or curated view layer when possible.
  • Add indexes that support your Custom SQL filters and update window.
  • Avoid SELECT * in Custom SQL; explicitly return only approved columns.
  • Avoid long-running joins against hot OLTP tables.
  • Keep batch size modest until query plans and sync duration are measured.
  • Restrict the MySQL account host pattern to the AIvis network path rather than %.
  • Do not enforce account-level MySQL TLS requirements until the deployed connection path supports them; use private networking or an approved proxy for protected routes.
  • Verify that query plans do not create heavy locks, full scans on large tables, or excessive temporary tables.

Verification

  1. Confirm the credential connects with the read-only account.
  2. In Automatic discovery, confirm the expected database tables and fields appear.
  3. In Custom SQL, validate that the query returns every configured column.
  4. Run an initial sync and inspect row count, indexed document count, and failures.
  5. Search for representative records by title and content.
  6. Confirm unselected tables, fields, and sensitive columns are absent from search.
  7. Update one test row and confirm the same document updates when an update field is configured.
  8. Test as a user outside the connector audience and confirm restricted documents do not appear.

Troubleshooting

SymptomLikely CauseResolution
Authentication failedWrong account, password, database, host, or port.Test from the deployment network with the same account and rotate the password if needed.
Permission deniedMissing SELECT on the selected table or view.Grant the minimum missing SELECT privilege to the read-only account.
No tables discoveredThe account cannot see any base tables, or only views were granted.Grant selected base tables for Automatic discovery, or use Custom SQL for views.
Custom SQL rejectedQuery is blank, has multiple statements, ends with a semicolon plus extra text, or does not start with SELECT / WITH.Use one read-only query and return explicit aliases for mapped columns.
Missing column errorThe query does not return the configured ID, title, content, metadata, or update column.Add aliases or update field mapping.
Invalid update fieldThe update column is not a MySQL datetime or timestamp value.Use a datetime-compatible field, or leave update field empty and accept full scans.
Duplicate or changing documentsNo stable identity exists, or the configured ID changes over time.Use primary keys, non-null unique keys, or a stable id_column.
Sync times outQuery cost exceeds max_execution_time or batch size is too high.Add indexes, reduce scope, lower batch size, or move indexing to a replica/view.
TLS-required connection failsThe server account or database proxy requires TLS options not exposed by the current credential form.Use a private endpoint/proxy that terminates or handles the required TLS path, or adjust deployment support before enforcing account-level TLS.