Multibyte Characters Get Corrupted When Inserting into Docker MySQL via PowerShell
Overview
While trying to seed test data into MySQL running on Docker, I ran into a problem where Japanese text was coming out garbled.
I was developing with Claude Code, and even after writing it into the notes, it kept making the same mistake. Eventually I switched to inserting data via a PHP script and that solved it.
The root cause turned out to be a PowerShell encoding issue, not the application.
Steps to Reproduce
Pipe a SQL file into MySQL from Windows PowerShell like this:
docker exec -i mysql mysql -u root -ppassword < seed.sql
Even though the SQL file is saved as UTF-8, Japanese characters get corrupted in the database.
Cause
Windows PowerShell’s default encoding is CP932 (Shift_JIS), so when you use a redirect (<), the file contents get converted to CP932.
Even a UTF-8 SQL file gets its character encoding destroyed by the time it passes through PowerShell to MySQL.
Solution
Insert data via an HTTP request to a PHP script.
# Check data before inserting
curl "http://localhost:8081/path/to/seed_runner.php?action=check"
# Insert test data
curl http://localhost:8081/path/to/seed_runner.php
Running SQL through PHP avoids the character encoding conversion problem entirely.
What Not to Do
- Don’t pipe SQL into MySQL with
docker exec mysql < file.sql - Don’t immediately blame the application’s character encoding handling when you see garbled text
The cause of encoding issues is often somewhere unexpected. In this case, the application itself was completely fine.
Aside
It’s a waste of tokens to burn through context just inserting dummy data when the actual app is working fine. If there’s a workaround, take it — your mental health will thank you.