Incorrect definition of table mysql.column_stats

Limited Time Offer!

For Less Than the Cost of a Starbucks Coffee, Access All DevOpsSchool Videos on YouTube Unlimitedly.
Master DevOps, SRE, DevSecOps Skills!

Enroll Now

If you are running a Laravel, PHP, or any backend application and suddenly your MySQL or MariaDB server starts throwing errors like:

Incorrect definition of table mysql.column_stats: expected column ‘min_value’ to have type varbinary(255), found varchar(255)

then you are dealing with a system-level database issue, not an application bug.

This problem is very common in:

  • Server migrations
  • XAMPP / LAMPP environments
  • MySQL ↔ MariaDB switching
  • Version upgrades or downgrades

In this guide, we will walk step-by-step through:

  • What the error actually means
  • Why it happens
  • How to diagnose it properly
  • Safe production fixes
  • Advanced debugging strategies
  • Prevention best practices

Understanding the Error

From your logs:

The error repeatedly says:

  • Expected: varbinary(255)
  • Found: varchar(255)

This mismatch exists in:

mysql.column_stats

This is not your application table — it is a MariaDB system table.


What is mysql.column_stats?

This table is used internally by MariaDB for:

  • Query optimization
  • Statistics calculation
  • Execution planning

If this table structure is wrong, MySQL/MariaDB may:

  • Log errors continuously
  • Fail optimization
  • Cause performance issues
  • In rare cases, fail to start

Root Cause (Real Scenario)

Based on your environment:

  • MariaDB Version: 10.4.28
  • Path: /opt/lampp/var/mysql

This clearly indicates:

You are using LAMPP (XAMPP for Linux).

Most likely causes:

  1. Database files copied from another server
  2. MariaDB version changed but system tables not upgraded
  3. Mix of MySQL and MariaDB data directories
  4. Incomplete upgrade using mysql_upgrade
  5. Manual data directory replacement

Step 1: Verify Your Database Version

Run:

mysql -u root -p -e "SELECT VERSION();"

Your output:

10.4.28-MariaDB

This confirms:

  • You are on MariaDB 10.4
  • Your system tables must match this version

Step 2: Check Table Structure

Run:

mysql -u root -p -e "USE mysql; SHOW CREATE TABLE column_stats\G"

If you see:

min_value varchar(255)
max_value varchar(255)

Then the issue is confirmed.


Step 3: Why This Mismatch Happens

MariaDB expects:

min_value VARBINARY(255)
max_value VARBINARY(255)

But your table has:

VARCHAR(255)

Why this is a problem

  • VARCHAR stores text with collation
  • VARBINARY stores raw binary

MariaDB uses binary for performance and precision in statistics.


Step 4: Safe Fix (Production Recommended)

Backup First (VERY IMPORTANT)

mysqldump -u root -p mysql column_stats > /root/column_stats_backup.sql

Fix the Table

Run:

mysql -u root -p -e "
USE mysql;
ALTER TABLE column_stats
MODIFY min_value VARBINARY(255) DEFAULT NULL,
MODIFY max_value VARBINARY(255) DEFAULT NULL;
"

Restart MariaDB (LAMPP)

/opt/lampp/lampp restartmysql

Verify Fix

tail -n 50 /opt/lampp/var/mysql/*.err

If no errors → issue resolved.


Step 5: Run Upgrade Tool (Recommended)

Even after fixing manually, always run:

/opt/lampp/bin/mysql_upgrade -u root -p --force

This will:

  • Fix all system tables
  • Align schema with current version
  • Prevent future errors

Restart again:

/opt/lampp/lampp restart

Step 6: If Error Still Persists

Then your system tables are more deeply inconsistent.

Run:

mysqlcheck -u root -p --all-databases --repair

Advanced Fix (Last Option)

If nothing works:

  1. Backup all databases
  2. Stop MySQL
  3. Reinitialize system tables
  4. Restore data

Real-World Debugging Insight

In production systems like yours (Laravel + Keycloak + Microservices), this issue can:

  • Break authentication indirectly
  • Cause query performance degradation
  • Trigger unexpected logs
  • Affect API response times

Even if your app “works”, this error must be fixed.


Common Questions

Is this a Laravel issue?

No. This is a database engine issue, not application code.


Can I ignore this error?

Not recommended. It may:

  • Affect performance
  • Lead to future crashes

Is it safe to run ALTER on system tables?

Yes, if:

  • You take backup
  • You only modify expected columns

Should I drop mysql database?

Never.

This will break:

  • Users
  • Permissions
  • Authentication

Why clearing browser cache sometimes “fixes” issues?

Because your system has:

  • Multiple layers (Keycloak + API + DB)

Sometimes UI works, but DB is still inconsistent.


Prevention Best Practices

1. Never mix MySQL and MariaDB data directories

2. Always run upgrade after version change

mysql_upgrade

3. Avoid copying raw /var/mysql directories

Instead use:

mysqldump → restore

4. Keep consistent environments

  • Same MariaDB version in dev and prod
  • Avoid XAMPP → production migration without cleanup

5. Monitor logs regularly

tail -f /opt/lampp/var/mysql/*.err

Final Summary

This issue happens because:

  • Your MariaDB expects VARBINARY
  • Your system table has VARCHAR

Fix is:

  1. Backup
  2. ALTER table
  3. Run mysql_upgrade
  4. Restart server

Final Production Command Set

mysqldump -u root -p mysql column_stats > /root/backup.sql

mysql -u root -p -e "
USE mysql;
ALTER TABLE column_stats
MODIFY min_value VARBINARY(255) DEFAULT NULL,
MODIFY max_value VARBINARY(255) DEFAULT NULL;
"

/opt/lampp/bin/mysql_upgrade -u root -p --force

/opt/lampp/lampp restart

Closing Note

This is a classic server-level issue that many developers misinterpret as an application bug. Fixing it correctly improves:

  • Stability
  • Performance
  • Reliability

Senior Software Development Engineer at Cotocus

Related Posts

How to Fix Laravel Migration Error: Field ‘id’ Doesn’t Have a Default Value in the Migrations Table

Limited Time Offer! For Less Than the Cost of a Starbucks Coffee, Access All DevOpsSchool Videos on YouTube Unlimitedly. Master DevOps, SRE, DevSecOps Skills! Enroll Now Laravel…

Read More

How to Install, Secure, and Tune MySQL 8.4 on Ubuntu 24.04 for Apache Event MPM and PHP-FPM

Limited Time Offer! For Less Than the Cost of a Starbucks Coffee, Access All DevOpsSchool Videos on YouTube Unlimitedly. Master DevOps, SRE, DevSecOps Skills! Enroll Now Running…

Read More

Complete Tutorial: Fixing MariaDB / MySQL Not Starting in XAMPP on Windows

Limited Time Offer! For Less Than the Cost of a Starbucks Coffee, Access All DevOpsSchool Videos on YouTube Unlimitedly. Master DevOps, SRE, DevSecOps Skills! Enroll Now Error:…

Read More

Secure phpMyAdmin on LAMPP (XAMPP for Linux): A Complete Guide

Limited Time Offer! For Less Than the Cost of a Starbucks Coffee, Access All DevOpsSchool Videos on YouTube Unlimitedly. Master DevOps, SRE, DevSecOps Skills! Enroll Now Admins…

Read More

Column not found: 1054 Unknown column ‘provider’ in ‘field list’ (Connection: mysql, SQL: insert into oauth_clients

Limited Time Offer! For Less Than the Cost of a Starbucks Coffee, Access All DevOpsSchool Videos on YouTube Unlimitedly. Master DevOps, SRE, DevSecOps Skills! Enroll Now when…

Read More

PHPMyAdmin Troubleshooting Advance Guides

Limited Time Offer! For Less Than the Cost of a Starbucks Coffee, Access All DevOpsSchool Videos on YouTube Unlimitedly. Master DevOps, SRE, DevSecOps Skills! Enroll Now PHPMyAdmin…

Read More
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments