Bug #51104 Low-level OS file errors are sent to client instead of meaningful MySQL errors
Submitted: 11 Feb 2010 14:57 Modified: 18 Jun 2012 7:32
Reporter: Philip Stoev Email Updates:
Status: Can't repeat Impact on me:
None 
Category:MySQL Server: Errors Severity:S3 (Non-critical)
Version:5.1,next-mr OS:Any
Assigned to: Jon Olav Hauglid CPU Architecture:Any

[11 Feb 2010 14:57] Philip Stoev
Description:
Certain DDL queries cause a less-than-meaningful error message, containing a OS-specific error code, to be returned to the user, instead of a more meaningful MySQL error.

This is a problem for the Random Query Generator, which may generate such queries. We would like to make any situation where an OS code is returned to be a fatal error that requires examination, but we can not until OS codes are being returned to the user as a matter of routine.

I understand the MySQL relies on FRM files and is thus indebted to the OS and the filesystem, however we do return proper errors in other cases.

How to repeat:
Those should return "database/table does not exist" or similar

mysql> rename table t1.t1 to t2.t2;
ERROR 1017 (HY000): Can't find file: './t1/t1.frm' (errno: 2)

mysql> create view t2.t2 as select 1;
ERROR 1 (HY000): Can't create/write to file './t2/t2.frm~' (Errcode: 2)

mysql> RENAME TABLE testdb_S . t1_base1_N  TO testdb_S . t1_base2_N  , testdb_S . t1_base1_N  TO testdb_N . t1_base1_N;
ERROR 1017 (HY000): Can't find file: './testdb_S/t1_base1_N.frm' (errno: 2)

mysql> ALTER DATABASE nosuch DEFAULT COLLATE  utf8_bin ;
ERROR 1 (HY000): Can't create/write to file './nosuch/db.opt' (Errcode: 2)

Suggested fix:
Convert the OS code into a mysql error code and send that to the client. Print OS codes only for unexpected situations that will not arise during the normal operation of the database.
[18 Jun 2012 7:32] Jon Olav Hauglid
Current trunk:

mysql> rename table t1.t1 to t2.t2;
ERROR 1017 (HY000): Can't find file: './t1/t1.frm' (errno: 2 - No such file
or directory)
mysql> create view t2.t2 as select 1;
ERROR 1049 (42000): Unknown database 't2'
mysql> rename table testdb_S.t1_base1_N to testdb_S.t1_base2_N;
ERROR 1017 (HY000): Can't find file: './testdb_s/t1_base1_N.frm' (errno: 2 -
No such file or directory)
mysql> alter database nosuch default collate utf8_bin;
ERROR 1 (HY000): Can't create/write to file './nosuch/db.opt' (Errcode: 2 -
No such file or directory)

Most of these improvements were done in the scope of Bug#48348