MySQL – Resolving mysql.proc Issues After Upgrade

MySQLmysql-5stored-procedures

Like many others, we upgraded our instance of MySQL from 5.0.* to 5.1.49. Since then, we've been running into an error that repeats itself when we perform certain actions:

  • Attempting to view or run a stored procedure
  • Attempting to insert into a table after adding a trigger for ON INSERT actions
  • Executing SELECT LENGHT(description), id FROM table (with the misspelling… when LENGTH was spelled correctly, the error did not display)

The error in question:

Column count of mysql.proc is wrong. Expected 20, found 16. The table is probably corrupted.

This has been reported as a bug (basically, lack of backwards compatibility), but there appears to be some confusion as to how to resolve the issue:

  • MySQL's documentation says the solution is to dump your stored procedures again after the upgrade to 5.1, then restore them again. The bug report I mentioned earlier shows that this has dubious results.
  • The bug report suggests running mysql_upgrade as a possible solution (albeit with some concerning warnings). However, it has been reported elsewhere that this solution doesn't always work.

I am in the unfortunate circumstance of not having a test box under which to test possible solutions as our development box is pending an OS upgrade to allow us to install the versions of MySQL we want to install. I am hesitant to try any solution on our production environment unless it has been verified as working by people who have encountered this issue.

What is the correct way to resolve this issue outside of waiting for an official patch or solution from MySQL?

While losing our stored procedures is not ideal, it is also a route we are willing to take to resolve the issue provided that there are no better alternatives and it will solve the issue cleanly.

Best Answer

Install a fresh copy of the same version of MySQL on another computer and copy its mysql.proc table to your broken server. That'll get you a clean, correct table. Then, recreate your stored procedures.