My method is a combination of the two: copy the data files from the Homebrew MySQL to Herd Pro to save the time that it would take to dump and import.
Note: this only works if your homebrew MySQL and Herd Pro MySQL are on the same minor version (8.0.1 to 8.0.3 would work; 8.0.x to 8.4.x would not).
Stop the homebrew MySQL service, if you haven’t already: brew services stop mysql (or maybe [email protected] if you’ve updated in the past few months)
Stop the Herd MySQL service, if you haven’t already, using the Herd services UI
Find the Herd data directory: right-click on the MySQL service and choose “Open data directory”
Copy or move the files to retain a backup
Find the homebrew data directory: in a terminal, run open $(brew --prefix)/var/mysql to open the directory in Finder
Copy the files to the Herd data directory
Restart Herd
After you’ve confirmed everything is fine, maybe delete the homebrew mysql data directory and brew uninstall [email protected]
I’ve recently been building an ecommerce app based on Laravel. Partway through development, we added geometry fields to a couple of tables in order to determine distances. I’ve been using this spatial package, so SQLite was not an option for my test suite.
As soon as I switched the testing database driver from SQLite to MariaDB, my tests immediately took an extra 12–13 seconds to run, regardless of whether I ran the entire test suite, a single file, or just one test.
This significantly lengthened the feedback loop when making changes to code and re-running tests.
So when I saw Jack Ellis mention that he uses MySQL for his test suite, it made me curious if he had the same issue.
He said that one of his test files runs 39 tests in < 2 seconds, so apparently it’s not been a problem for him.
Context
I’m using the LazilyRefreshDatabase trait added in Laravel 8.62.0 on my entire test suite
Many of my tables have constrained foreign keys referencing other tables
Comparisons
I decided to do some digging; here are comparisons using four different platforms for the same test in my application.
MariaDB
I’ve been using MariaDB as the main database platform on my development machine for years. Currently I’m on version 10.6.4.
In-Memory SQLite Database
I temporarily disabled the geometry features and tried the in-memory SQLite database (DB_CONNECTION=:memory:); it performed much better for the same tests:
A single test too <1s to run
An entire file with 16 tests took ~7s to run
SQLite File Database
I then tried with an SQLite file (DB_CONNECTION=sqlite), and it performed about the same:
A single test took ~1s to run
An entire file with 16 tests took ~7s to run
MySQL 8
I have an installation of MySQL 8 set up for one app that uses some specific MySQL 8 and I figured why not give that a try too.
Here are the results:
A single test took ~1.5s to run
An entire file with 16 tests took ~6.5s to run
Summary
For some reason, MariaDB takes approximately 12–13 seconds to tear down and recreate the database before starting to run tests, but MySQL is much faster.
While testing MariaDB, I opened the raw data directory for the database, and noticed chunks of files being removed and recreated at a time, so perhaps the foreign key constraints are (part of) the culprit here.
I do have 77 databases with ~3800 tables in my MariaDB installation built up from various projects over the years. It seems unlikely, but theoretically possible, that the server size could be part of the problem too.
I think I’ll experiment with switching back to MySQL as my development platform of choice.
Have you run into this same issue? Have any tips or tricks? Let me know in the comments.