Fixing MySQL server error “Column count doesn’t match value count at row 1” during upgrade

  Kiến thức lập trình

I had the following error message when trying to upgrade a MySQL server on a local development environment:

2024-05-05T02:12:15.152874Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.37) starting as process 31012
2024-05-05T02:12:15.157727Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2024-05-05T02:12:15.640312Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2024-05-05T02:12:16.434948Z 4 [System] [MY-013381] [Server] Server upgrade from '80036' to '80037' started.
2024-05-05T02:12:17.935591Z 4 [ERROR] [MY-013178] [Server] Execution of server-side SQL statement 'INSERT IGNORE INTO mysql.db VALUES ('localhost', 'performance_schema', 'mysql.session','Y','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N'); ' failed with error code = 1136, error message = 'Column count doesn/'t match value count at row 1'.
2024-05-05T02:12:17.938560Z 0 [ERROR] [MY-013380] [Server] Failed to upgrade server.
2024-05-05T02:12:17.938613Z 0 [ERROR] [MY-010119] [Server] Aborting

I tried running sudo mysqld --upgrade=MINIMAL, and also achieved the same result by adding upgrade=MINIMAL to the file located at /etc/mysql/mysql.conf.d/mysqld.cnf before running sudo systemctl start mysql. This gave the following error log messages:

2024-05-05T02:25:13.151136Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.37) starting as process 32487
2024-05-05T02:25:13.155795Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2024-05-05T02:25:13.642077Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2024-05-05T02:25:14.433640Z 0 [Warning] [MY-013378] [Server] Server upgrade is required, but skipped by command line option '--upgrade=MINIMAL'.
2024-05-05T02:25:14.527872Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2024-05-05T02:25:14.527917Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
2024-05-05T02:25:14.542608Z 0 [Warning] [MY-013139] [Server] Cannot load from mysql.db. The table is probably corrupted!
2024-05-05T02:25:14.542651Z 0 [Warning] [MY-013139] [Server] Cannot load from mysql.columns_priv. The table is probably corrupted!

I solved the issue by re-initializing the MySQL server. First, I moved the data away and recreated the datadir:

sudo systemctl stop mysql
sudo mv /var/lib/mysql /var/lib/mysql-backup
sudo mkdir /var/lib/mysql
sudo chown mysql:mysql mysql

Then I ran the following command to reinitialize MySQL: sudo mysqld --initialize -u root

At this point, I restarted the service with sudo systemctl start mysql and took note of the structure in mysql.db, although I also could have exported the table structure in SQL. I then switched the datadir folders around to recover my initial database:

sudo systemctl stop mysql
sudo mv /var/lib/mysql /var/lib/mysql0
sudo mv /var/lib/mysql-backup /var/libmysql
sudo systemctl start mysql

I was then able to remove the extra column, stop the service, remove upgrade=MINIMAL from the /etc/mysql/mysql.conf.d/mysqld.cnf file and restart the service. The upgrade was completed successfully and everything works.

LEAVE A COMMENT