Skip to main content
GrN.dk

Main navigation

  • Articles
  • Cases
  • Contact
  • Your Digital Project Manager
  • About Greg Nowak
  • Services
  • Portfolio
  • Container
    • Excel Freelancer
    • Kubuntu - tips and tricks
    • Linux Apache MySQL and PHP
    • News
    • Image Gallery
User account menu
  • Log in

Breadcrumb

  1. Home

MySQL Zero-Date Import Errors: Fix Them Safely

By Greg Nowak. Last updated 2026-07-09.

A MySQL import that fails on '0000-00-00', '0000-00-00 00:00:00', or a date like '2012-00-00' is usually not just an import problem. It is a legacy data contract meeting a stricter database. That often appears during host moves, CMS upgrades, agency handovers, and staging restores where an old dump is being loaded onto a newer MySQL server.

The risky fix is to weaken the whole server because one import is blocked. The better fix is to identify the active SQL mode, find the affected columns, and choose between a narrow import workaround and a proper schema cleanup.

Why Zero Dates Fail on Newer MySQL

Current MySQL defaults include strict validation along with NO_ZERO_DATE and NO_ZERO_IN_DATE. Those modes control whether MySQL accepts all-zero dates and dates where the month or day is zero. MySQL still documents these as legacy-compatible values, but the zero-date mode names are deprecated as standalone switches and are expected to be folded into strict behavior in a future release.

For business and operations teams, the useful takeaway is simple: zero dates are usually technical debt. They may have meant “not set yet” in an old application, but newer database defaults treat impossible dates as something that should be made explicit with NULL, a valid date, or a clear business status field.

Check the Mode Before Changing It

Start with the connection that will run the import. The session value is what matters to that connection; the global value only initializes new sessions.

SHOW SESSION VARIABLES LIKE 'sql_mode';
SHOW GLOBAL VARIABLES LIKE 'sql_mode';

SELECT @@SESSION.sql_mode, @@GLOBAL.sql_mode;

This is where many quick fixes go wrong. SET GLOBAL does not repair the client session you already opened, and it can change behavior for unrelated applications that connect later.

Find the Columns That Still Depend on Zero Dates

Before deciding on a fix, audit the schema. This query finds date-like columns that still define all-zero defaults:

SELECT TABLE_NAME, COLUMN_NAME, COLUMN_TYPE, COLUMN_DEFAULT
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_SCHEMA = 'your_database'
  AND DATA_TYPE IN ('date','datetime','timestamp')
  AND COLUMN_DEFAULT IN ('0000-00-00', '0000-00-00 00:00:00');

If the result is one or two columns, you may have a contained cleanup. If it appears across many tables, treat it as a migration risk, not a console annoyance.

Situation Best move Why
One blocked legacy restore Use a session-only import bridge It keeps the exception limited to the import connection.
Repeated failures in deployments or refreshes Fix schema and application handling The same hidden assumption will keep returning.
Shared MySQL server Avoid casual global changes Other apps may inherit behavior they were not tested against.
Legacy app awaiting retirement Document a temporary server-level exception Sometimes stability wins, but the exception needs an owner and end date.
Decision guide for zero-date import errors.

The Safer Short-Term Import Bridge

If the restore is urgent and cleanup cannot happen first, remove only the zero-date modes for the current session. Run the import from that same session, then put the session mode back.

SET @original_sql_mode := @@SESSION.sql_mode;

SET SESSION sql_mode = TRIM(BOTH ',' FROM REPLACE(REPLACE(
  CONCAT(',', @@SESSION.sql_mode, ','),
  ',NO_ZERO_IN_DATE,', ','),
  ',NO_ZERO_DATE,', ','
));

-- Run the legacy import in this same connection.

SET SESSION sql_mode = @original_sql_mode;

This is safer than pasting a generic SET GLOBAL sql_mode = ... command because it does not change future connections for the whole server. It also preserves the rest of the current session mode instead of replacing it with a guessed list.

There is one practical catch: if your import tool opens a separate connection, the session change must be applied inside that connection. Changing one interactive MySQL client will not affect another process.

The Long-Term Fix: Make “Unknown” Explicit

Where you control the application, replace impossible dates with a real data rule. In many systems, that means making the column nullable and using NULL for “not known yet.” Test this on a copy first, especially if old PHP, CMS, or reporting code compares directly against '0000-00-00'.

ALTER TABLE your_table
  MODIFY your_date_column DATE NULL DEFAULT NULL;

UPDATE your_table
SET your_date_column = NULL
WHERE your_date_column = '0000-00-00';

Use the real column type in your own table. For DATETIME columns, check for '0000-00-00 00:00:00'. If application code used zero dates as a status flag, update that code at the same time instead of preserving the old ambiguity under a new schema.

When a Global Change Is Justified

A global or persisted change can be reasonable for an owned legacy environment, but it should be an infrastructure decision, not an emergency paste. MySQL distinguishes session, global, and persisted system variable changes. Session changes normally affect only the current client. Global changes affect new sessions. Persisted changes survive restarts by writing server configuration.

If you need a temporary server-wide exception, document why it exists, who depends on it, how it was tested, and when it should be removed. That runbook matters because zero-date issues often surface again during the next upgrade, replication change, or vendor handover.

Practical Rule

Use a session-level bridge to get a one-off legacy import unstuck. Use schema and data cleanup when the application will keep running. Treat zero dates as a migration signal, not just a MySQL error message.

If this came up during a client handover, hosting move, or CMS rebuild, Greg can help scope the import path, cleanup work, and rollout plan before it becomes a launch-week surprise.

Related on GrN.dk

  • AI Crawler Control for Business Websites: Protect Content Without Sacrificing Search Visibility
  • Importing External Data into Drupal: A Practical Migration Plan
  • NGINX 1.30 changed upstream connection reuse by default: what to check before you upgrade

Need help with this kind of work?

Plan a safer MySQL migration Get in touch with Greg.

Sources

  • MySQL 9.7 Reference Manual: Server SQL Modes
  • MySQL 9.7 Reference Manual: SET Syntax for Variable Assignment
  • MySQL 9.7 Reference Manual: Date and Time Data Types
  • MySQL 9.7 Reference Manual: INFORMATION_SCHEMA COLUMNS Table
Last modified
2026-07-09

Tags

  • mysql
  • database
  • migration
  • DevOps

Review Greg on Google

Greg Nowak Google Reviews

 

Illustrated infographic summarizing: Copilot Has Repo-Level Metrics Now. What Should Teams Measure?
Copilot Has Repo-Level Metrics Now. What Should Teams Measure?
2026-07-29

GitHub’s repo-level Copilot metrics show where AI is active, but not whether it adds value. This scorecard connects usage with delivery, quality, and cost.

Illustrated infographic summarizing: Not Every AI Job Needs an Instant Answer: Batch the Backlog
Not Every AI Job Needs an Instant Answer: Batch the Backlog
2026-07-28

Move delay-tolerant AI work into dependable batch queues to cut processing costs without compromising quality, data controls, or urgent workflows.

Illustrated infographic summarizing: A stray Set-Cookie can waste your CDN: audit the cache at the edge
A stray Set-Cookie can waste your CDN: audit the cache at the edge
2026-07-27

Cloudflare Cache Response Rules can recover wasted CDN capacity, but first you need a route-level audit of public, personal and authenticated responses.

Illustrated infographic summarizing: Shorter TLS certificates expose every renewal you never automated
Shorter TLS certificates expose every renewal you never automated
2026-07-26

Shorter TLS lifetimes leave less room for manual handoffs and faulty deploy hooks. Build a renewal path that protects service availability.

Illustrated infographic summarizing: One Timeout, Two Orders: Make AI Actions Safe to Retry
One Timeout, Two Orders: Make AI Actions Safe to Retry
2026-07-25

A timed-out AI action may already have succeeded. Stable keys, durable ledgers, queues and stored results prevent a routine retry from duplicating real work.

Illustrated infographic summarizing: Your AI Visibility Dashboard Needs a Methodology, Not More Charts
Your AI Visibility Dashboard Needs a Methodology, Not More Charts
2026-07-24

A practical framework for measuring AI-search visibility with fixed prompts, repeated tests, separate metrics, retained evidence, and honest reporting.

Illustrated infographic summarizing: AI Admin APIs Are Here—But Your Directory Is Still the Source of Truth
AI Admin APIs Are Here—But Your Directory Is Still the Source of Truth
2026-07-23

New AI admin APIs can automate access and spend controls, but reliable governance still starts with authoritative directory data and clear ownership.

Illustrated infographic summarizing: OpenAI Presence Arrived—But Is Your Workflow Ready for an Agent?
OpenAI Presence Arrived—But Is Your Workflow Ready for an Agent?
2026-07-22

Before an AI agent can take on real work, its workflow needs clear scope, permissions, handoffs, evaluation cases, and production monitoring.

Illustrated infographic summarizing: Chatbot Transcripts Quietly Became a Retention and Redaction Problem
Chatbot Transcripts Quietly Became a Retention and Redaction Problem
2026-07-21

Chatbot transcripts spread across providers, logs and support tools. Here is how to map each copy, redact sensitive data and test deletion properly.

Illustrated infographic summarizing: Cloudflare Service Keys Stop in September: Find Every Caller
Cloudflare Service Keys Stop in September: Find Every Caller
2026-07-20

Cloudflare Service Keys stop working on September 30, 2026. Here is how to find every caller, move to scoped API tokens and avoid a late outage.

More articles
RSS feed

GrN.dk web platforms, web optimization, data analysis, data handling and logistics.