Mysql – Forcing thesql client to use IP over hostname (from python)

MySQL

Is there any way to force a mysql client to prefer using an IP address over a hostname for self-identification to a server? I am running Python 2.7.12 and MySQLdb 1.2.5 to connect to a MySQL server and get the following error:

django.db.utils.OperationalError: (1130, "Host '<myHostName>' is not allowed to connect to this MySQL server")

When I try to connect from the command line via invoking mysql -h -p (etc.), it works as expected. I am assuming it is because the client is using the IP address to identify itself to the server. (myHostName does not resolve to the correct IP from the server's vantage when checking it with host myHostName from the server)

Is there anyway to define this or otherwise force the use of an IP address?

MySQL version is 5.6.31-0ubuntu0.14.04.2-log (Ubuntu)

Thanks.

Best Answer

The use of hostnames is decided on the server side, not on the client side. You cannot change anything on the client to affect this.

To use only IP addresses, the MySQL server must be started with the --skip-name-resolve option, or skip-name-resolve set in my.cnf.