MySQL 8 is available as an optional secondary database server running alongside the default MySQL 5.7/Percona instance. This allows you to test applications against MySQL 8 or run multiple database versions simultaneously.
Enable MySQL 8 during the initial setup:
dev setupIf you've already set up your environment:
mkdir -p conf/mysql8
dev rebuildMySQL 8 runs on a different port to avoid conflicts with the default database:
- Host:
localhost(from your machine) ordb8(from containers) - Port:
3308(note: different from default 3306) - Root password: Same as your main MySQL instance (set in conf/mysql)
mysql -h 127.0.0.1 -P 3308 -u root -pUse the hostname db8 and standard port 3306:
$connection = new PDO('mysql:host=db8;port=3306;dbname=mydb', 'root', 'password');The standard dev mysql command connects to the default database. For MySQL 8, use the direct connection method above.
Key differences in MySQL 8:
- Authentication: Default authentication plugin changed to
caching_sha2_password - Performance: Improved query optimizer and performance
- JSON: Enhanced JSON functionality
- Window Functions: Support for window functions
- CTEs: Common Table Expressions (WITH clause)
- Roles: Better role-based access control
Magento 2.4.4+ officially supports MySQL 8. In env.php:
'db' => [
'connection' => [
'default' => [
'host' => 'db8',
'dbname' => 'magento',
'username' => 'root',
'password' => 'yourpassword',
'port' => '3306'
]
]
]In .env:
DB_CONNECTION=mysql
DB_HOST=db8
DB_PORT=3306
DB_DATABASE=laravel
DB_USERNAME=root
DB_PASSWORD=yourpassword
You can run both MySQL 5.7 and MySQL 8 simultaneously:
- MySQL 5.7/Percona:
dbon port 3306 - MySQL 8:
db8on port 3308
This allows you to:
- Test compatibility before upgrading
- Run different projects on different MySQL versions
- Migrate data between versions
MySQL 8 uses a separate Docker volume for data persistence. To make it persistent in your development directory:
cd ~/development
dev down --remove-orphans
dev volume rm mysql8
mkdir mysql8
dev volume mysql8 mysql8
dev setupCheck if MySQL 8 is running:
dev ps | grep db8View MySQL 8 logs:
dev logs db8Test connectivity:
mysql -h 127.0.0.1 -P 3308 -u root -p -e "SELECT VERSION();"If you get "Authentication plugin 'caching_sha2_password' cannot be loaded", your MySQL client may be outdated. Either:
- Update your MySQL client
- Create users with the older authentication method in MySQL 8