
Security News
Socket Releases Free Certified Patches for Nuxt Security Vulnerabilities
Socket releases free Certified Patches for high-severity Nuxt vulnerabilities, including server-side remote code execution through server island props.
@mastra/mysql
Advanced tools
Affected versions:
MySQL storage implementation for Mastra, providing persistent storage for threads, messages, workflows, traces, and more with connection pooling and transaction support.
npm install @mastra/mysql
import { MySQLStore } from '@mastra/mysql';
const store = new MySQLStore({
connectionString: 'mysql://user:password@localhost:3306/mastra',
});
// Create a thread
await store.saveThread({
thread: {
id: 'thread-123',
resourceId: 'resource-456',
title: 'My Thread',
metadata: { key: 'value' },
createdAt: new Date(),
updatedAt: new Date(),
},
});
// Add messages to thread
await store.saveMessages({
messages: [
{
id: 'msg-789',
threadId: 'thread-123',
role: 'user',
content: { content: 'Hello' },
resourceId: 'resource-456',
createdAt: new Date(),
},
],
});
// Query threads and messages
const savedThread = await store.getThreadById({ threadId: 'thread-123' });
const messages = await store.listMessages({ threadId: 'thread-123' });
import { Mastra } from '@mastra/core';
import { MySQLStore } from '@mastra/mysql';
export const mastra = new Mastra({
storage: new MySQLStore({
connectionString: 'mysql://user:password@localhost:3306/mastra',
}),
});
MySQLStore supports two connection methods:
1. Connection String
const store = new MySQLStore({
connectionString: 'mysql://user:password@localhost:3306/mastra',
});
2. Host/Port/Database
const store = new MySQLStore({
host: 'localhost',
port: 3306,
user: 'mastra',
password: 'mastra',
database: 'mastra',
});
ssl: Enable SSL or provide custom SSL options (true | false | object)max: Maximum pool connections (default: 10)database: Override the database name parsed from the connection stringwaitForConnections: Queue requests when the pool is full (default: true, host config only)queueLimit: Maximum queued connection requests, 0 for unlimited (default: 0, host config only)skipDefaultIndexes: Skip creating the built-in performance indexes during setup (default: false)indexes: Additional custom indexes to create during setupmysql2saveThread({ thread }): Create or update a threadgetThreadById({ threadId }): Get a thread by IDdeleteThread({ threadId }): Delete a thread and its messagessaveMessages({ messages }): Save multiple messages in a transactionlistMessages({ threadId, perPage?, page? }): Get messages for a thread with paginationdeleteMessages(messageIds): Delete specific messagesThe test suite reads the following variables to connect to MySQL, falling back to the defaults shown:
MYSQL_HOST (default: localhost)MYSQL_PORT (default: 3306)MYSQL_USER (default: mastra)MYSQL_PASSWORD (default: mastra)MYSQL_DB (default: mastra)Unit tests run without a database:
pnpm test src/storage/index.unit.test.ts
Integration tests use Docker to start a MySQL instance, run the suite, and clean up afterward:
# Ensure Docker is running
pnpm test
FAQs
MySQL provider for Mastra - db storage capabilities
The npm package @mastra/mysql receives a total of 822 weekly downloads. As such, @mastra/mysql popularity was classified as not popular.
We found that @mastra/mysql demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 7 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Socket releases free Certified Patches for high-severity Nuxt vulnerabilities, including server-side remote code execution through server island props.

Security News
An open letter signed by 50 companies, from NVIDIA and Microsoft to Mistral and Hugging Face, urges Washington not to restrict open weight AI.

Security News
/Research
A fake corepack.org site is impersonating the Node.js tool and delivers an infostealer and proxyware to developers who download it.