【问题标题】:MySql Running on Windows but Cannot Connect Using Command lineMySql 在 Windows 上运行但无法使用命令行连接
【发布时间】:2016-05-05 09:20:33
【问题描述】:

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

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

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

有人可以帮忙吗?

【问题讨论】:

  • 您检查服务是否已启动并运行?
  • 您是否检查了常用的东西,例如端口号、基于软件的防火墙等?
  • 服务在 3306 端口上运行良好。
  • 你在命令提示符下有管理员权限吗?
  • 是的,“以管理员身份运行”没有帮助。

标签: mysql windows database-connection


【解决方案1】:

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

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

【讨论】:

  • 我提到服务正常运行,甚至可以使用工作台客户端连接。刚刚从远程机器检查,能够连接,所以不是防火墙问题。但是服务器中的本地命令提示符仍然无法连接。这会造成不便,因为 mysqldump 也不可用。
【解决方案2】:

只是自己解决了问题。

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

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

【讨论】:

    猜你喜欢
    • 2014-06-19
    • 2020-04-27
    • 1970-01-01
    • 1970-01-01
    • 2023-02-06
    • 2022-09-26
    • 1970-01-01
    • 2012-05-03
    • 1970-01-01
    相关资源
    最近更新 更多