DEV Community

Cover image for When is a MySQL error not a MySQL error
Mark Sta Ana
Mark Sta Ana

Posted on • Originally published at booyaa.wtf on

When is a MySQL error not a MySQL error

Photo by Cassidy Mills on Unsplash

I came across this error recently: Mysql2::Error: Can't connect to MySQL server on 'some-db-server.example.com' (113)

A quick search on the Internet, resulted in various Q & A sites hinting at a connectivity/routing issue to/from the MySQL server.

Whilst this was probably enough information for me to fix, if the problem exists on a 3rd party's infrastructure you want to provide a bit more information.

The first port of call was to see if the error code 113 appears in the MySQL reference. You can imagine my surprise when I couldn't find 113 anywhere in this chapter.

Luckily there is help available from MySQL in the form of a utility called perror that allows you to look up MySQL error codes.

By typing perror along with error code, you'll get the following:

$ perror 113
OS error code 113:  No route to host
Enter fullscreen mode Exit fullscreen mode

So the reason we can't find this error in either the Client or Server sections of the MySQL reference manual is that it's an operating system error.

The operating system in question is Linux, so we know we're looking for C error number codes (errno.h). If you've got access to the kernel source you can find it in /usr/src/linux-source-<VERSION>/include/uapi/asm-generic/errno.h if you don't have the source installed you can see it see a definition of 113 GitHub:

#define    EHOSTUNREACH    113    /* No route to host */
Enter fullscreen mode Exit fullscreen mode

So armed with this information, I could contact the 3rd party and ask them to check routing and firewall rules between us and the database server.

Top comments (1)

Collapse
 
pojntfx profile image
Felicitas Pojtinger

Consider using mariadb instead of mysql, most contributors switched teams a while back. apt install mysql installs mariadb for you anyways (even though most people probably don't realize) ;)