MySql在Windows上运行但无法使用命令行连接

时间:2016-05-05 09:20:34

标签: mysql windows database-connection

我在Windows Server 2008上使用MySql 5.6(64位,无安装),服务运行正常,MySql Workbench可以成功连接。但是,当从localhost尝试使用命令提示符连接时,我收到以下错误:

e:\ mysql \ bin> mysql -uroot -p 输入密码:***********

ERROR 2003(HY000):无法连接到'localhost'上的MySQL服务器(10061)

有人可以帮忙吗?

2 个答案:

答案 0 :(得分:0)

打开服务(Start->Run-> "services.msc")并检查MySQL是否正在运行。如果不是 - 运行它。

如果它已经运行,那么很可能你有一个防火墙阻止到端口3306的连接(或者你决定让MySQL运行的那个端口),你需要允许到那个端口的传入连接(允许连接取决于什么您正在使用的软件。

答案 1 :(得分:0)

我自己想出了问题。

MySql只能监听Windows Server的固定IP(例如10.33.40.26)。在Windows" hosts"中为该IP添加localhost别名文件解决了这个问题。

10.33.40.26 localhost

主机文件的位置可能因Windows的不同版本而异;以下是修改后文件最终的样子:

C:\>more c:\windows\system32\drivers\etc\hosts
# Copyright (c) 1993-2009 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
#      102.54.94.97     rhino.acme.com          # source server
#       38.25.63.10     x.acme.com              # x client host

# localhost name resolution is handled within DNS itself.
127.0.0.1       localhost
10.33.40.26       localhost
#       ::1             localhost