Does MySQL Work With TypeORM?

Fully CompatibleLast verified: 2026-02-26

TypeORM has first-class support for MySQL and works seamlessly as its primary ORM layer, making them an excellent pairing for Node.js/TypeScript applications.

Quick Facts

Compatibility
full
Setup Difficulty
Easy
Official Integration
Yes ✓
Confidence
high
Minimum Versions
MySQL: 5.7
TypeORM: 0.2.0

How MySQL Works With TypeORM

TypeORM is purpose-built to handle MySQL connections and provides a robust abstraction layer over the MySQL2/promise driver. When you configure TypeORM with MySQL, you get a fully-featured ORM experience including entity decorators, query builders, migrations, and relationship management. The developer experience is smooth—you define your database schema as TypeScript classes with decorators, and TypeORM handles connection pooling, query generation, and type safety automatically. TypeORM's query builder is particularly powerful with MySQL, allowing both fluent API chains and raw SQL when needed. Connection pooling is handled intelligently by default, making it suitable for production applications. The migrations system works well with MySQL's DDL support, and TypeORM correctly handles MySQL-specific features like AUTO_INCREMENT, ENUM types, and JSON columns (MySQL 5.7+). Performance is generally excellent since TypeORM generates efficient SQL queries, though you should be mindful of N+1 query problems when loading relationships.

Best Use Cases

Building REST APIs where you need type-safe database access with automatic validation
Enterprise applications requiring complex relationships and transaction support across multiple entities
Microservices architectures where each service has its own MySQL database managed by TypeORM
Real-time applications with WebSocket support that need reliable, pooled database connections

Quick Setup

bash
npm install typeorm mysql2 reflect-metadata
typescript
import { DataSource } from 'typeorm';
import { User } from './entities/User';

const AppDataSource = new DataSource({
  type: 'mysql',
  host: 'localhost',
  port: 3306,
  username: 'root',
  password: 'password',
  database: 'myapp',
  entities: [User],
  synchronize: false,
  logging: false,
});

AppDataSource.initialize().then(() => {
  console.log('Connected to MySQL');
  
  const userRepo = AppDataSource.getRepository(User);
  userRepo.find({ where: { active: true } })
    .then(users => console.log(users));
}).catch(error => console.error('Connection failed', error));

Known Issues & Gotchas

warning

Lazy loading relations doesn't work outside of an active database context, causing 'relation not loaded' errors

Fix: Use eager loading or explicitly load relations with .leftJoinAndSelect() in your query builder before returning entities

warning

MySQL ENUM columns have limited flexibility; changing enum values requires ALTER TABLE operations that can lock tables in production

Fix: Consider using VARCHAR with constraints instead of ENUM for columns that may change, or use a separate lookup table

critical

Connection pool exhaustion under high concurrency can cause 'Error: connect ECONNREFUSED' intermittently

Fix: Configure appropriate pool size in DataSource options (default is 10) and monitor connection usage with .query() method metrics

info

MySQL strict mode and TypeORM's default date handling can cause type coercion issues with NULL values

Fix: Use proper nullable decorators (@Column({ nullable: true })) and validate date fields before database operations

Alternatives

  • Prisma with MySQL - newer ORM with excellent type generation and simpler API
  • Sequelize with MySQL - older mature ORM, less TypeScript-focused but very stable
  • MikroORM with MySQL - lightweight alternative with better performance for simple queries

Resources

Related Compatibility Guides

Explore more compatibility guides