Database (MySQL/MariaDB)
MageBox runs MySQL and MariaDB in Docker containers, with each version on a unique port to allow multiple versions simultaneously.
Supported Versions
MySQL
| Version | Port | Magento Compatibility |
|---|---|---|
| MySQL 5.7 | 33057 | Magento 2.4.0 - 2.4.3 |
| MySQL 8.0 | 33080 | Magento 2.4.4+ (recommended) |
| MySQL 8.4 | 33084 | Magento 2.4.7+ |
MariaDB
| Version | Port | Magento Compatibility |
|---|---|---|
| MariaDB 10.4 | 33104 | Magento 2.4.0 - 2.4.5 |
| MariaDB 10.6 | 33106 | Magento 2.4.4+ |
| MariaDB 11.4 | 33114 | Magento 2.4.7+ |
Configuration
Selecting Database Version
In .magebox.yaml:
services:
mysql: "8.0" # Use MySQL 8.0Or for MariaDB:
services:
mariadb: "10.6" # Use MariaDB 10.6WARNING
Use either mysql OR mariadb, not both.
Connection Details
Default Credentials
| Setting | Value |
|---|---|
| Host | 127.0.0.1 |
| Port | Depends on version (see table above) |
| Username | root |
| Password | magebox |
| Database | Project name from .magebox.yaml |
Magento Configuration
In app/etc/env.php:
'db' => [
'table_prefix' => '',
'connection' => [
'default' => [
'host' => '127.0.0.1:33080', // Port for MySQL 8.0
'dbname' => 'mystore',
'username' => 'root',
'password' => 'magebox',
'model' => 'mysql4',
'engine' => 'innodb',
'initStatements' => 'SET NAMES utf8;',
'active' => '1',
]
]
],Magento Install Command
php bin/magento setup:install \
--db-host=127.0.0.1:33080 \
--db-name=mystore \
--db-user=root \
--db-password=magebox \
# ... other optionsDatabase Commands
Open Database Shell
magebox db shellThis connects to the correct database with proper credentials.
Import Database
# From SQL file
magebox db import dump.sql
# From gzipped file
magebox db import dump.sql.gzImport includes a real-time progress bar showing:
- Percentage complete
- Bytes imported / total size
- Transfer speed (MB/s)
- Estimated time remaining (ETA)
Importing dump.sql.gz into database 'mystore' (magebox-mysql-8.0)
Importing: ████████████████████░░░░░░░░░░░░░░░░░░░░ 52.3% (156.2 MB/298.5 MB) 24.5 MB/s ETA: 6sExport Database
# To default file ({project}.sql)
magebox db export
# To specific file
magebox db export backup.sql
# Gzipped
magebox db export backup.sql.gz
# To stdout
magebox db export -Direct MySQL Access
# Connect directly with mysql client
mysql -h 127.0.0.1 -P 33080 -u root -pmagebox mystoreDocker Container
Viewing Container Status
# List running containers
docker ps | grep mysql
# Check specific container
docker ps -f name=magebox-mysqlContainer Logs
# View MySQL logs
docker logs magebox-mysql-8.0
# Follow logs
docker logs -f magebox-mysql-8.0Data Persistence
Database data is stored in Docker volumes:
# List volumes
docker volume ls | grep magebox
# Inspect volume
docker volume inspect magebox-mysql-8.0-dataMultiple Database Versions
You can run multiple database versions simultaneously for different projects:
Project A (.magebox.yaml):
name: project-a
services:
mysql: "8.0" # Port 33080Project B (.magebox.yaml):
name: project-b
services:
mysql: "5.7" # Port 33057Both containers run simultaneously on different ports.
Performance Tuning
Docker Resource Limits
For large databases, you may need to adjust Docker resources:
- Open Docker Desktop settings
- Resources → Advanced
- Increase Memory (4GB+ recommended for Magento)
- Increase CPU
MySQL Configuration
You can mount a custom MySQL config file for production-like performance or to control features like binary logging:
# Create custom config
cat > ~/.magebox/docker/mysql-custom.cnf << EOF
[mysqld]
innodb_buffer_pool_size = 1G
innodb_log_file_size = 256M
max_connections = 200
skip-log-bin
EOFFor MariaDB, use ~/.magebox/docker/mariadb-custom.cnf instead.
After creating or modifying the config file, restart MageBox to apply:
magebox restartTroubleshooting
Connection Refused
SQLSTATE[HY000] [2002] Connection refusedSolutions:
Check Docker is running:
bashdocker psVerify correct port:
bash# Check which database version you're using cat .magebox.yaml | grep mysqlStart services:
bashmagebox global start
Access Denied
ERROR 1045 (28000): Access denied for user 'root'@'localhost'Solution: Use correct credentials:
mysql -h 127.0.0.1 -P 33080 -u root -pmageboxNote: Password is magebox, not magento.
Database Too Large to Import
For large databases:
# Increase timeout
mysql -h 127.0.0.1 -P 33080 -u root -pmagebox \
--max_allowed_packet=1G \
mystore < dump.sql
# Or split the import
split -l 100000 dump.sql dump_part_
for f in dump_part_*; do
mysql -h 127.0.0.1 -P 33080 -u root -pmagebox mystore < $f
doneContainer Won't Start
# Check container logs
docker logs magebox-mysql-8.0
# Remove and recreate
docker rm -f magebox-mysql-8.0
magebox global startPort Already in Use
# Find what's using the port
lsof -i :33080
# Stop conflicting service or use different database versionBackup Best Practices
Regular Backups
# Create timestamped backup
magebox db export backup-$(date +%Y%m%d-%H%M%S).sql.gzBefore Major Changes
# Backup before upgrade
magebox db export pre-upgrade.sql.gz
# Run upgrade
php bin/magento setup:upgrade
# If something goes wrong
magebox db import pre-upgrade.sql.gzAutomated Backups
Create a cron job or script:
#!/bin/bash
# ~/.magebox/scripts/backup.sh
cd /path/to/project
magebox db export ~/backups/mystore-$(date +%Y%m%d).sql.gz
# Keep only last 7 days
find ~/backups -name "mystore-*.sql.gz" -mtime +7 -deleteSwitching Database Versions
To switch from MySQL 8.0 to MySQL 5.7:
Export your database:
bashmagebox db export backup.sqlUpdate
.magebox.yaml:yamlservices: mysql: "5.7"Restart services:
bashmagebox restartImport database:
bashmagebox db import backup.sqlUpdate
app/etc/env.phpwith new port (33057).