Download the PHP package gigerit/laravel-mysql-optimizer without Composer
On this page you can find all versions of the php package gigerit/laravel-mysql-optimizer. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package laravel-mysql-optimizer
MySQL Optimizer
A Laravel package for optimizing MySQL/MariaDB database tables with support for both synchronous and queued execution.
Why use this package?
MySQL's OPTIMIZE TABLE
statement reorganizes tables and compacts wasted space, resulting in:
- Faster queries through improved data packing and reduced fragmentation
- Less disk I/O for full table scans
- Reduced storage footprint via better space utilization
Ideal for tables with frequent INSERT
, UPDATE
, and DELETE
operations.
Requirements
- Laravel 8.x – 12.x (auto-discovered service provider)
- MySQL 5.7+/8.0+ or MariaDB (uses INFORMATION_SCHEMA and OPTIMIZE TABLE)
Installation
Publish the configuration (optional):
Configuration
The package reads the default database to optimize from config/mysql-optimizer.php
:
- Set
DB_DATABASE
in your.env
, or overridemysql-optimizer.database
at runtime. - When the
--database=default
option is used, the action resolves toconfig('mysql-optimizer.database')
.
CLI usage
Options:
--database=default
: Database name to optimize. Usedefault
to useconfig('mysql-optimizer.database')
.--table=*
: Repeatable. If omitted, all tables in the target database are optimized.--queued
: Queue the optimization as a job instead of running synchronously.--no-log
: Disable job logging; only applies when--queued
is used.
Examples
Optimize all tables in the default database:
Optimize specific tables:
Optimize a specific database:
Queue optimization for all tables:
Queue optimization for selected tables with logging disabled:
Using the Job directly
When using queued execution, ensure a worker is running:
Scheduling
Optimize all tables weekly on Sunday at 02:00 as a queued job:
Optimize selected high-traffic tables daily at 03:00 as a queued job:
Or schedule the console command to run synchronously:
Behavior and logging
- Synchronous runs show a progress bar and success counts in the console.
- Queued runs log start/completion, and per-table results (unless
--no-log
is used).
Exceptions
MySQLOptimizer\Exceptions\DatabaseNotFoundException
MySQLOptimizer\Exceptions\TableNotFoundException
Operational notes
OPTIMIZE TABLE
may lock tables. Prefer running during low-traffic windows.- Ensure the DB user has sufficient privileges to run
OPTIMIZE TABLE
and accessINFORMATION_SCHEMA
.
Testing
Compatibility
- Laravel 8.x – 12.x
Contributing
We welcome contributions! Please see:
- Contributing Guidelines
- Code of Conduct
Standards
This package follows:
License
This package is open-sourced software licensed under the MIT license.
Credits
Updated, Extended & Maintained by gigerIT
Original idea for Laravel 8 by Zak Rahman
💡 Pro tip: schedule regular optimizations using Laravel's task scheduler for automated maintenance.
All versions of laravel-mysql-optimizer with dependencies
illuminate/database Version ^8.0|^9.0|^10.0|^11.0|^12.0
illuminate/bus Version ^8.0|^9.0|^10.0|^11.0|^12.0
illuminate/queue Version ^8.0|^9.0|^10.0|^11.0|^12.0
illuminate/support Version ^8.0|^9.0|^10.0|^11.0|^12.0