Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use the option skip-name-resolve when using MySQLdb for Python?

I try to connect to database in a domain from my virtual machine. It works on XP, but somehow does not work on Win7 and quitting with: "OperationalError: (1042, "Can't get hostname for your address")"

Now I tried disable Firewall and stuff, but that doesn't matter anyway. I don't need the DNS resolving, which will only slow everything down. So I want to use the option "skip-name-resolve", but there is no my.ini or my.cnf when using MySQLdb for Python, so how can I still use this option?

Thanks for your help -Alex

like image 299
CreeTar Avatar asked Jul 12 '11 17:07

CreeTar


People also ask

What is Skip name resolve?

This is a command-line option for the mariadbd & mysqld commands. Don't resolve hostnames. All hostnames are IP's or 'localhost'. See also: mariadbd & mysqld for MariaDB Enterprise Server 10.6, in 10.6 CS, in 10.5 ES, in 10.5 CS, in 10.4 ES, in 10.4 CS, in 10.3 ES, in 10.3 CS, in 10.2 ES, and in 10.2 CS.

What is MySQLdb in Python?

MySQLdb is an interface for connecting to a MySQL database server from Python. It implements the Python Database API v2. 0 and is built on top of the MySQL C API. Packages to Install. mysql-connector-python mysql-python.

How do I find my Python database username and password?

Checking Login Credentials with Python and SQLite f"SELECT username from users WHERE username='{username}' AND password = '{password}'; Now we have the ingredients for a simple Python script to check whether a username/password combination exists in the database and print a user message accordingly.

How do I get MySQL connector in Python?

Install MySQL Driver Python needs a MySQL driver to access the MySQL database. In this tutorial we will use the driver "MySQL Connector". We recommend that you use PIP to install "MySQL Connector". PIP is most likely already installed in your Python environment.


2 Answers

Add the following line(skip-name-resolve) in the /etc/mysql/my.cnf file

[mysqld]
port = 3306
socket = /tmp/mysql.sock
skip-locking
skip-name-resolve

And restart the mysql server

like image 90
Ranzit Avatar answered Sep 19 '22 12:09

Ranzit


This is an option which needs to be set in the MySQL configuration file on the server. It can't be set by client APIs such as MySQLdb. This is because of the potential security implications.

That is, I may want to deny access from a particular hostname. With skip-name-resolve enabled, this won't work. (Admittedly, access control via hostname is probably not the best idea anyway.)

like image 28
Michael Mior Avatar answered Sep 18 '22 12:09

Michael Mior