I use my remote MySQL database during long time.
But today I suddenly have found that I cannot connect to the database. I have got an error.
"Can't get hostname from your ip address".
I haven't changed anything in MySQL settings.
What's the problem?
Just add below in my.ini
or my.cnf
.
[mysqld]
skip-name-resolve
Linux:
Otherwise, start MySQL server with the following flag:
sudo service --skip-name-resolve
For more information: http://dev.mysql.com/doc/refman/5.0/en/host-cache.html
I've got the same error message on windows. I found my problem is the local server host file. Check the localhost or any hostname you use in the file c:\windows\system32\drivers\etc\host
My original host file: 127.0.0.1 localhost ::1 localhost
I just delete the second line and use the first line only: 127.0.0.1 localhost
Then, problem solved, for my problem. Hope it helps.
I ran into this problem when installing MySQL 8 on a Windows 10 machine. Most of the solutions found on the internet are setting skip-name-resolve
which never worked for me. At last I found out this one which worked for me:
netsh winsock reset
Then reboot the computer. Also try set
127.0.0.1 localhost
in %windir%\System32\drivers\etc\hosts
if needed.
I know this question was asked quite some time ago and most people have figured it out by now, but for those who haven't, here was my solution:
Add the port number with the server name in you connection string
connectionstring = "server=server;Port=3306;User Id=UserNAme;password=password;Persist Security Info=True;database=DatabaseName;convert zero datetime=true";
来源:https://stackoverflow.com/questions/5118151/mysql-error-cant-get-hostname-from-your-ip-address