Unknown MySQL server host 'localhost' 问题

本地mvn clean install  出现Unknown MySQL server host 'localhost' 问题

异常日志:

Factory method 'mysqlServer' threw exception; nested exception is com.wix.mysql.exceptions.CommandFailedException: Command 'CREATE USER 'user'@'%' IDENTIFIED BY 'password';' on schema 'information_schema' failed with errCode '1' and output 'mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 2005 (HY000): Unknown MySQL server host 'localhost' (0)

原因:

连接mysql数据库的时候会出现:mysql error 2005 - Unknown MySQL server host 'localhost'(0)错误;
当检查连接信息,连接属性信息,用户名和密码都是正确的,IP地址为:localhost,在有网络的情况下都能正常打开数据库,但是一断网就出错了。

解决:

在创建mysql连接的时候在主机或IP地址一栏填写:127.0.0.1而不要填写localhost,然后在断网的情况下进行测试会发现是可以连接成功的。 错误原因是:在有网络的情况,会自动解析localhost为127.0.0.1,而断网的情况下,localhost只是一个字符串,不代表一个ip地址。 mysql配置文件的存储在hosts文件中,其位置在: Windows:c:\windows\system32\drives\etc\hosts Linux:/etc/hosts 打开配置文件可看到在文件的末尾处,localhost的主机ip设置为127.0.0.1。

苹果Mac OS系统修改Hosts文件的方法 : https://laod.cn/hosts/mac-os-xiugai-hosts.html

 

评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值