苏州吴中区电路维修:ERROR 1042 (00000): Can't get hostname for your address解决方案

来源:百度文库 编辑:偶看新闻 时间:2024/05/03 20:33:49

ERROR 1042 (00000): Can't get hostname for your address解决方案  

2011-04-19 13:49:37|  分类: MySQL技术专栏 |  标签: |字号大中小 订阅

第一步:
.安装完mysql后
[root@sv245 tmp]# mysqladmin -hlocalhost -uroot password '123456'
[root@sv245 tmp]# mysql -uroot -p123456
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.1.41-ndb-7.0.13-cluster-gpl MySQL Cluster Server (GPL)

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> select user,host,password from user;
+------+-----------+-------------------------------------------+
| user | host      | password                                  |
+------+-----------+-------------------------------------------+
| root | localhost | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| root | sv245     |                                           |
| root | 127.0.0.1 |                                           |
| root | ::1       |                                           |
|      | localhost |                                           |
|      | sv245     |                                           |
+------+-----------+-------------------------------------------+
6 rows in set (0.00 sec)

mysql> update user set host='%' where host='localhost';
Query OK, 2 rows affected (0.02 sec)
Rows matched: 2  Changed: 2  Warnings: 0

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> select user,host,password from user;
+------+-----------+-------------------------------------------+
| user | host      | password                                  |
+------+-----------+-------------------------------------------+
| root | %         | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| root | sv245     |                                           |
| root | 127.0.0.1 |                                           |
| root | ::1       |                                           |
|      | %         |                                           |
|      | sv245     |                                           |
+------+-----------+-------------------------------------------+
6 rows in set (0.00 sec)

mysql> exit
Bye
[root@sv245 tmp]# service mysql restart

第二步:
[root@sv245 mysql]# cp my-huge.cnf /etc/my.cnf
[root@sv245 mysql]# vi /etc/my.cnf
在配置文件中增加:
[mysqld]下增加下面一句话:
skip-name-resolve
[root@sv245 mysql]# service mysql restart
ok,可以通过外部工具测试连接了
windows系统下测试如下:
C:\Documents and Settings\lidw>mysql -h 192.168.0.245 -uroot -p123456
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1 to server version: 5.1.41-ndb-7.0.13-cluster-gpl-l
og

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql>
ok,连接成功:

注释:

#1:去掉mysql启动参数中的skip-name-resolve ,然后jdbc连接串用ip地址和主机名均可。

#2:如果保留启动参数skip-name-resolve 的话,在jdbc连接串中只能使用IP地址的方式连接数据库。