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

MySql Running on Windows but Cannot Connect Using Command line

我在 Windows Server 2008 上使用 MySql 5.6(64 位,无需安装),服务 运行 很好,MySql Workbench 可以成功连接。但是,当尝试使用本地主机的命令提示符进行连接时,出现以下错误:

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

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

有人可以帮忙吗?

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

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

刚刚自己弄明白了问题

MySql 只能监听 Windows 服务器的固定 IP(例如 10.33.40.26)。在 Windows "hosts" 文件中为该 IP 添加本地主机别名解决了问题。

10.33.40.26 本地主机

hosts 文件的位置可能因 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