January 15, 2026 8 min read Magento 2 Database Performance

Optimizing Database Queries in Magento

Learn how to profile, index, and optimize MySQL queries in Magento 2 to drastically improve your store response times.

# Optimizing Database Queries in Magento

Slow queries are a common performance bottleneck in large-scale Magento 2 deployments. Database profiling and index optimization can improve your API and frontend load times significantly.

## Profiling Slow Queries

To find bottlenecks, enable the Magento database profiler in `app/etc/env.php`:

```php
'db' => [
'connection' => [
'default' => [
'profiler' => [
'class' => '\Magento\Framework\DB\Profiler',
'enabled' => true
]
]
]
]
```

Alternatively, use MySQL's Slow Query Log to track queries taking longer than 1 second.