How to Configure Haystack MySQL Read Only Access

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up haystack mysql read only access by creating a limited database user. Then you pass those read-only credentials to your Haystack SQL component. Teams often start by reusing a shared app account for early tests. That account usually has permission to alter tables or delete rows. If a language model writes a bad query, it can break production data. Giving the pipeline a read-only role stops those write commands at the database. How to set up haystack mysql read only access in your data

Your coding agents run with your access.

Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.

You set up haystack mysql read only access by creating a limited database user. Then you pass those read-only credentials to your Haystack SQL component. Teams often start by reusing a shared app account for early tests. That account usually has permission to alter tables or delete rows. If a language model writes a bad query, it can break production data. Giving the pipeline a read-only role stops those write commands at the database.

How to set up haystack mysql read only access in your database

Start inside your MySQL server before you touch any Python code. An admin creates a dedicated database user just for the Haystack pipeline. You grant this new user select permissions on the target schema or tables. Do not grant insert, update, delete, or drop privileges to this role. If the pipeline only needs three tables, grant select on those three tables. Leave sensitive billing or user credential tables out of the grant list.

Next, you can enforce read-only rules at the session or instance level. Many teams point their Haystack app at a MySQL read replica. A read replica rejects write queries by default and protects the primary database. Even if someone misconfigures user grants, the replica blocks data changes. It also keeps heavy AI search queries from slowing down customer transactions. Finally, place the new database credentials into your secret manager for the app.

How Haystack runs SQL queries with read-only credentials

In Haystack, a query component or custom tool connects to your MySQL database. During startup, the component reads the database host, user, and password from secrets. When a user asks a question, the language model drafts a SQL statement. The Haystack component sends that SQL statement over the open MySQL session.

MySQL checks the user permissions before it runs the incoming query. If the model sends a select query on an allowed table, MySQL returns rows. The component passes those rows back to the pipeline to build an answer. If the model tries to drop a table, MySQL rejects the statement right away. The pipeline gets an error message back, and your records stay safe.

Auditor Read-Only Access + MySQL Access Governance: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

What native MySQL roles solve and where gaps remain

Native MySQL permissions are great at stopping unauthorized writes and schema changes. They decide which user can log in and which tables that user can read. A read replica also helps protect primary database CPU and memory during spikes.

Still, database grants only check table access, not what each query returns. Once a select permission is granted, the user can read every row and column by default. If a table holds emails, phone numbers, or card numbers, the query pulls them. Data masking rewrites matched fields in results so sensitive values stay protected. Also, static credentials stored in app settings are hard to rotate across many services. Shared database users make it tough to see which prompt triggered a slow query. Teams often need query logs tied to identity and automatic masking on results.

Check MySQL queries and results on the wire

MySQL grants control who logs in. They do not check single queries or mask sensitive columns once a session starts. With hoop.dev, you run an open-source proxy, a sidecar for your MySQL. It runs next to MySQL, RDS, or Aurora and reads the MySQL wire protocol.

Multi-statement batches and prepared queries are split and checked one by one by hoop.dev guardrails. When a rule refuses a query, MySQL returns a native error packet with your message. On the response path, hoop.dev data masking rewrites string values in returned rows that match your rules. Every query and decision is logged per resource. See the MIT-licensed project on GitHub.

Frequently asked questions

Can a MySQL read-only user still lock tables or slow down the database?

Yes, a read-only user can still run huge joins or full table scans. You can limit query run time in MySQL and route traffic to a read replica.

Should I give Haystack access to the whole schema or specific views?

Granting select permissions on specific SQL views is much safer than full schema grants. Views let you hide columns that hold emails, phone numbers, or national IDs.

How do I handle connection limits when many Haystack workers run at once?

Set a maximum connection limit on the MySQL user account itself. This keeps a busy AI pipeline from using up all available database connections.

The query runs. The emails stay hidden.