Mysqldump Encoding: How to Prevent Broken Characters in Database Exports

Illustrated infographic summarizing: Mysqldump Encoding: How to Prevent Broken Characters in Database Exports

By Greg Nowak. Last updated 2026-11-21.

Broken customer names or product descriptions can turn a routine database migration into a launch blocker. When that happens, changing the dump encoding is tempting. First, establish whether the text was correct before the export.

The fault may sit in stored data, column definitions, connection settings or the tool displaying the file. For business owners and agency teams, the useful deliverable is a restored database that passes agreed checks, with someone responsible for resolving exceptions.

Check the source before changing the export

Choose representative records before running the migration: names containing æ, ø or é; curly quotes; currency symbols; multilingual content; and emoji where supported. Record their IDs and expected text so the receiving team can repeat the checks.

Inspect column definitions as well as connection settings. A database default alone cannot establish how every text field is declared. MySQL exposes this information through its INFORMATION_SCHEMA COLUMNS table:

SHOW VARIABLES LIKE 'character_set_%';
SHOW VARIABLES LIKE 'collation_%';

SELECT TABLE_NAME, COLUMN_NAME, DATA_TYPE,
       CHARACTER_SET_NAME, COLLATION_NAME
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_SCHEMA = 'DATABASE_NAME'
  AND CHARACTER_SET_NAME IS NOT NULL
ORDER BY TABLE_NAME, ORDINAL_POSITION;

These session settings describe the connection running the query. Check the application's connection separately; your SQL client may use different settings.

If a value looks wrong, compare its stored bytes with what the application displays. Substitute real table names and known record IDs:

SELECT id, customer_name, HEX(customer_name)
FROM customers
WHERE id IN (123, 456);

HEX() provides evidence for diagnosis. It does not identify a universal repair. Preserve the original data before testing conversions: repeated attempts to “fix UTF-8” can make recovery harder.

Choose the export path from the evidence

Finding Next step Acceptance check
Valid utf8mb4 text Export through an utf8mb4 connection Representative text survives restoration
Valid latin1 and Unicode columns Test an utf8mb4 export before considering legacy settings Values survive conversion and reload
Text already looks damaged Investigate bytes and application settings separately Document existing damage before migration
Binary fields need checking Consider --hex-blob Binary values remain identical
Non-transactional tables exist Arrange appropriate locking or a maintenance window Related records remain consistent
Separate text preservation, data repair and export consistency before choosing flags.

A latin1 column does not automatically require a latin1 dump. MySQL normally converts query results into the connection's requested character set, using the column's declared encoding. Its connection charset documentation explains that boundary.

That conversion depends on truthful metadata. UTF-8 bytes stored under an incorrect latin1 declaration need investigation. Avoid exporting everything as latin1 merely because an old CMS contains some latin1 columns.

Make the normal export explicit

For valid source text, use utf8mb4. It supports four-byte Unicode characters that utf8mb3 cannot represent, as described in MySQL's utf8mb4 documentation. Spell out the name rather than using the deprecated utf8 alias.

For an InnoDB database, this Bash command is a practical starting point. Replace the host, user and database placeholders:

mysqldump --host=SOURCE_HOST -u USER -p \
  --single-transaction --quick \
  --default-character-set=utf8mb4 \
  --result-file=dump.sql DATABASE_NAME

Keep the default SET NAMES output; avoid --skip-set-charset. --quick streams rows. --single-transaction provides InnoDB snapshot consistency, not consistency for changing MyISAM or MEMORY tables. Prevent schema changes during the dump.

If required, add --routines --events with suitable privileges. These options and limitations are covered in the mysqldump manual.

The export charset controls text transfer. It does not upgrade the recreated columns to utf8mb4. Treat schema conversion as a separate, tested change.

Avoid an unnecessary file conversion

Using --result-file lets mysqldump write the file directly. This also avoids a historical Windows trap: Windows PowerShell 5.1 output redirection can produce UTF-16 text.

The warning needs a version qualifier. Microsoft documents that PowerShell 7.4 and later preserve native command output bytes when redirecting stdout. Do not assume every PowerShell version behaves alike, or resave the dump in an editor because its preview looks odd.

Prove the restore on the intended target

Use a disposable database on the target version. The following commands use Bash input redirection; confirm the target host before running them:

mysql --host=TARGET_HOST -u USER -p \
  -e "CREATE DATABASE restore_test CHARACTER SET utf8mb4"

mysql --host=TARGET_HOST -u USER -p \
  --default-character-set=utf8mb4 restore_test < dump.sql

Check command exit status and retain error output. Then compare the selected records, exact row counts where appropriate, required database objects and application pages. Test creating and editing multilingual content too: an application can display migrated text correctly while still writing new text through a misconfigured connection.

An unknown-collation error calls for a target compatibility review. Changing the file encoding will not make an unsupported collation available.

On Linux, retain a transfer checksum and inspect the dump's charset instruction:

grep -m 1 -i 'SET NAMES' dump.sql
sha256sum dump.sql

A matching checksum proves the transferred file matches the original. It does not prove the database is correct.

Hand over evidence the next team can use

Include the exact command, client and server versions, charset findings, checksum, restore duration, validation records and unresolved anomalies. State clearly whether restoration was tested. Agree who checks the application and who authorises cutover.

Also decide how writes made after the snapshot will reach the new system. A successful rehearsal does not settle the final migration window or rollback plan.

If legacy data or several suppliers make ownership unclear, Greg can help coordinate the diagnosis, restore rehearsal and migration handoff, giving your team a concrete basis for deciding when to proceed.

Related on GrN.dk

Need help with this kind of work?

Plan a tested database migration with Greg Get in touch with Greg.

Sources

Latest articles

Let’s Encrypt moves to 64-day certificates on 10 February 2027. Check when each site renews, test the reload and verify the certificate visitors receive.

Work out which Drupal 10 sites can move to Drupal 11 by 9 December, who can resolve each blocker and how to test publishing and rollback before launch.

See how SharePoint access changes reach internal AI search, and test how long revoked content can still appear in results, generated answers, and citations.

At month-end, reconcile Shopify Payments against your bank statement and e-conomic. Use the payout ID to trace fees, refunds, and payouts that reach your bank the following month.

Trace an intermittent NGINX 502 through Cloudflare, upstream attempts, and application logs so you can see where the request failed and who should pick it up.

Find the apps, scripts and printers that still send mail through Microsoft 365 with a mailbox password, then test a replacement before the December 2026 change.

Find subscriptions and insurance expenses in e-conomic that should be spread over several months. See how AI reads the supporting documents and how your finance lead approves the proposed allocations.

Before relying on an AI project briefing, check which files it covered. A practical workflow for tracking documents, recording gaps and verifying key claims.

Check whether your contact form rejects missing or invalid Turnstile tokens, handles failed checks for genuine users and delivers accepted enquiries to your team.

Compare Bing citations, identifiable AI visits and verified enquiries to see which pages deserve attention before you increase your AI search marketing budget.