MySQL 1042 Can't get hostname for your address Problem Analysis Solution Process [Comment 1] former colleague penguin said he installed mysql 5.5, found that when using the mysql client remote connection, the error 1042-Can't get hostname for your address is reported, but the permission has been granted and the grant is successful. This error indicates that "your address cannot obtain the host name", and I thought of the skip-name-resolve parameter. Official documentation: -- skip-name-resolveUse IP addresses rather than host names when creating grant table entries. this option can be useful if your DNS does not work. -- skip-name-resolveDo not resolve host names when checking client connections. use only IP numbers. if you use this option, all Host column values in the grant tables must be IP numbers or localhost. see Section 7.7.11, "How MySQL Uses DNS ".
mysql> show variables like '%skip_name_resolve%';+-------------------+-------+| Variable_name | Value |+-------------------+-------+| skip_name_resolve | ON |+-------------------+-------+1 row in set (0.00 sec)mysql> set global skip_name_resolve=0;ERROR 1238 (HY000): Variable 'skip_name_resolve' is a read only variablemysql>
Failed. It seems that only my. cnf is modified under the [mysqld] node.
Skip-name-resolve # ignore the host name to access lower_case_table_names = 1 # ignore the case sensitivity of the database table name
Restart MySQLD process. [Comment 2] comments from former colleague Penguin:
mysql -h 192.168.1.101 -u root -p
My local mysql.192.168.1.101 is a local IP address. Grant all privileges on *. * to 'hive' @ '192. 168.1.101 'identified by 'hive' with grant option; this means that the connection fails and the permission is incorrect. How can this problem be solved. View official documentation: hostnameVariable Name hostnameVariable Scope GlobalDynamic Variable No Permitted ValuesType stringThe server sets this variable to the server host name at startup.
[html] mysql> show variables like '%hostname%'; +---------------+-------------------------------------------+ | Variable_name | Value | +---------------+-------------------------------------------+ | hostname | xxxxx.china.online.xx.com | +---------------+-------------------------------------------+ 1 row in set (0.00 sec) mysql> set global hostname='xxxxx2.china.online.xx.com'; ERROR 1238 (HY000): Variable 'hostname' is a read only variable mysql>
Failed. Only my. cnf is modified. Under the mysqld Option
[Mysqld] # comment out the parameter. mysql cannot access it directly using the local ip address # hostname
Restart the mysqld service.