mysql解决Unknown Error无法正常显示错误信息
症状
- 场景1:执行如下非常简单的建表语句也会报错,提示 Unknown error 1049,根本看不出什么原因(通常 error 1049意味着db不存在)。
mysql> create table testdb.t1(f1 int);
ERROR 1049 (42000): Unknown error 1049
- 场景2:开发同事反馈代码报错 unknown error 1048,虽然知道 error 1048 指的是向not null字段插入null值,但不知道是哪个表哪个字段,难以定位问题。
mysql> insert into testdb.t2(id,name) values(1,null);
ERROR 1048 (23000): Unknown error 1048
确认过程
执行
select @@version;
确认版本为 5.7.xx场景1 的mysql错误日志有如下 ERROR,大致意思是 Error message file 应该包含1116个错误信息,但实际上只有1081个,猜测有升级过mysql版本。
2019-06-25T03:13:54.200233Z 0 [ERROR] Error message file '/usr/local/mysql/share/english/errmsg.sys' had only 1081 error messages,
but it should contain at least 1116 error messages.
Check that the above file is the right version for this program!
- 场景2 的mysql错误日志有大量的如下 Warning:
2020-12-24T13:36:09.372628+08:00 0 [Warning] InnoDB: Table mysql/innodb_index_stats has length mismatch in the column name table_name. Please run mysql_upgrade
2020-12-24T13:36:09.372689+08:00 0 [Warning] InnoDB: Table mysql/innodb_table_stats has length mismatch in the column name table_name. Please run mysql_upgrade
2020-12-24T13:36:09.372700+08:00 0 [Warning] InnoDB: Table mysql/innodb_index_stats has length mismatch in the column name table_name. Please run mysql_upgrade
解决办法
- 1、找到mysql安装包的路径,比如
/usr/local/mysql
,确认存在 share 目录
find / -name mysql
ll /usr/local/mysql/share
- 2、在my.cnf中添加
lc-messages-dir
参数
lc-messages-dir=/usr/local/mysql/share/
lc_messages=en_US
- 3、重启数据库后即可正常显示报错信息
mysql> create table testdb.t1(f1 int);
ERROR 1049 (42000): Unknown database 'testdb'
mysql> insert into testdb.t2(id,name) values(1,null);
ERROR 1048 (23000): Column 'name' cannot be null
- 4、如果还不行,可以将 share 目录改名,再从生产环境拷贝一份同版本的 share 目录过来