MySQL:是否可以缩短错误消息?

时间:2021-12-17 00:59:48

I have heard a lot of people complain about this, and justifiably so. Many MySQL error messages are ridiculously long:

我听说很多人抱怨这个,理所当然。许多MySQL错误消息非常长:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near... 

This gets especially annoying in environments that only show you the first half of that string. So the question is: Is it possible to get a shorter version of that string? Something like: Syntax error near... - which is really the juicy part of that message.

这在仅显示该字符串的前半部分的环境中尤其令人讨厌。所以问题是:是否有可能获得该字符串的较短版本?类似的东西:...附近的语法错误 - 这实际上是该消息的多汁部分。

1 个解决方案

#1


21  

Note:The steps provided here are only for Linux, you might be using some other OS then use respective editor and commands

注意:此处提供的步骤仅适用于Linux,您可能正在使用其他操作系统,然后使用相应的编辑器和命令

MySQL stores error message file at /usr/share/mysql/english/errmsg.sys where english is the language you want to use.

MySQL将错误消息文件存储在/usr/share/mysql/english/errmsg.sys中,其中english是您要使用的语言。

Note:You need to have super user privileges

注意:您需要拥有超级用户权限

Step 1. Take backup of existing errmsg.sys (so that you can revert if some problem occured

步骤1.备份现有的errmsg.sys(以便在发生某些问题时可以恢复

  $sudo cp /usr/share/mysql/english/errmsg.sys ~/errmsg.sys.bkp

Step 2. Open /usr/share/mysql/english/errmsg.sys in vi editor.

步骤2.在vi编辑器中打开/usr/share/mysql/english/errmsg.sys。

$sudo vi /usr/share/mysql/english/errmsg.sys

Step 3. Search for "You have an" in errmsg.sys

步骤3.在errmsg.sys中搜索“你有一个”

in vi editor for searching try this way-->  /You have an [press enter]

It will get you to the string "You have an error...." as show in screen-shot MySQL:是否可以缩短错误消息?

它会让你看到屏幕截图中显示的字符串“你有一个错误......”

Step 4. Edit that error message as per your need. I've deleted string You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the and kept just right syntax to use

步骤4.根据需要编辑该错误消息。我删除了字符串你的SQL语法有错误;查看与您的MySQL服务器版本相对应的手册,并保留恰当的语法

Check below screen-shot. MySQL:是否可以缩短错误消息?

检查下面的屏幕截图。

Step 5. Save and Exit.

步骤5.保存并退出。

in vi editor to save and exit-->   :x! [press enter]     here ! is added to override read-only file

Step 6. Restart mysql service.

步骤6.重启mysql服务。

$sudo mysql restart

step 7. check error message (I'm checking in phpMyAdmin)

步骤7.检查错误消息(我正在检查phpMyAdmin)

MySQL:是否可以缩短错误消息?

In this answer I've updated error message You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near... similarly you can update other standard error message as well.

在这个答案中,我更新了错误消息您的SQL语法中有错误;检查与您的MySQL服务器版本对应的手册,以便在附近使用正确的语法...同样,您也可以更新其他标准错误消息。

Hope it helped ! :D

希望它有所帮助! :d

#1


21  

Note:The steps provided here are only for Linux, you might be using some other OS then use respective editor and commands

注意:此处提供的步骤仅适用于Linux,您可能正在使用其他操作系统,然后使用相应的编辑器和命令

MySQL stores error message file at /usr/share/mysql/english/errmsg.sys where english is the language you want to use.

MySQL将错误消息文件存储在/usr/share/mysql/english/errmsg.sys中,其中english是您要使用的语言。

Note:You need to have super user privileges

注意:您需要拥有超级用户权限

Step 1. Take backup of existing errmsg.sys (so that you can revert if some problem occured

步骤1.备份现有的errmsg.sys(以便在发生某些问题时可以恢复

  $sudo cp /usr/share/mysql/english/errmsg.sys ~/errmsg.sys.bkp

Step 2. Open /usr/share/mysql/english/errmsg.sys in vi editor.

步骤2.在vi编辑器中打开/usr/share/mysql/english/errmsg.sys。

$sudo vi /usr/share/mysql/english/errmsg.sys

Step 3. Search for "You have an" in errmsg.sys

步骤3.在errmsg.sys中搜索“你有一个”

in vi editor for searching try this way-->  /You have an [press enter]

It will get you to the string "You have an error...." as show in screen-shot MySQL:是否可以缩短错误消息?

它会让你看到屏幕截图中显示的字符串“你有一个错误......”

Step 4. Edit that error message as per your need. I've deleted string You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the and kept just right syntax to use

步骤4.根据需要编辑该错误消息。我删除了字符串你的SQL语法有错误;查看与您的MySQL服务器版本相对应的手册,并保留恰当的语法

Check below screen-shot. MySQL:是否可以缩短错误消息?

检查下面的屏幕截图。

Step 5. Save and Exit.

步骤5.保存并退出。

in vi editor to save and exit-->   :x! [press enter]     here ! is added to override read-only file

Step 6. Restart mysql service.

步骤6.重启mysql服务。

$sudo mysql restart

step 7. check error message (I'm checking in phpMyAdmin)

步骤7.检查错误消息(我正在检查phpMyAdmin)

MySQL:是否可以缩短错误消息?

In this answer I've updated error message You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near... similarly you can update other standard error message as well.

在这个答案中,我更新了错误消息您的SQL语法中有错误;检查与您的MySQL服务器版本对应的手册,以便在附近使用正确的语法...同样,您也可以更新其他标准错误消息。

Hope it helped ! :D

希望它有所帮助! :d