MySQL错误2003:无法在本地主机上连接MySQL服务器

时间:2021-10-17 01:58:21

I've been given the task of running a program that relies on a MySQL database, specifically, the 3.23.42 version. I have to install MySQL, run a .batch file that reads an SQL file (to create the required tables and such), then run the program. Seems simple enough.

我的任务是运行一个程序,它依赖于一个MySQL数据库,特别是3.23.42版本。我必须安装MySQL,运行一个.批处理文件来读取SQL文件(创建所需的表等等),然后运行程序。似乎很简单。

I got as far as installing MySQL. I was expecting it to ask username and passwords and such, as was my experience with installing SQL Server and MySQL version 5 (and later), but it needed nothing from me. Attempts to run the .batch file, however, yields the error:

我已经安装了MySQL。我希望它能询问用户名和密码,比如我在安装SQL Server和MySQL版本5(以及后来的版本)时的经验,但它不需要我的任何东西。但是,尝试运行.batch文件会产生错误:

"MySQL Error 2003: Can't connect to MySQL server on 'localhost' "

“MySQL错误2003:无法连接到本地主机上的MySQL服务器”

So I ran Command prompt as an administrator, went to the MySQL directory, and ran "mysql". It gave me the same error as above.

因此我作为管理员运行命令提示符,进入MySQL目录,运行“MySQL”。它给了我和上面一样的错误。

Running the commands "mysqld-nt" or "mysqld" didn't do anything, so I'm assuming there's another problem at work here. Neither did I find any 'mysql' in the running services or process.

运行“mysqld-nt”或“mysqld”命令没有做任何事情,所以我假设这里还有一个问题。我也没有在运行的服务或过程中发现任何“mysql”。

At this point, it doesn't matter if the program runs or not. I need the database up and running first.

在这一点上,程序运行与否并不重要。我需要先运行数据库并运行。

Although I've used MySQL before, I can't say I have that much experience with it, and it had always been up and running already; this is the first time I'm deploying it myself.

虽然我以前使用过MySQL,但我不能说我有这么多的经验,而且它一直都在运行;这是我第一次亲自部署。

Of note is that: I haven't tried to reinstall the program yet, although I'm not sure if it will fix anything. I've installed MyODBC-3.15.05, if it means anything (part of the instructions). I'm using Windows 7, 32-bit (I have heard MySQL doesn't like to play nice with Windows 7). I'm using this setup as both the server and the client; had the entire process been successful, I was to do the same thing on another computer. No computer actually uses another as a server. I don't exactly know what services to look for in the services list.

值得注意的是:我还没有尝试重新安装程序,尽管我不确定它是否能修复任何问题。我安装了MyODBC-3.15.05,如果它意味着什么(部分说明)。我使用的是Windows 7, 32位(我听说MySQL不喜欢使用Windows 7),我使用这个设置作为服务器和客户端;如果整个过程都是成功的,我就会在另一台电脑上做同样的事情。没有一台计算机真正使用另一台作为服务器。我不知道在服务列表中查找什么服务。

Is there anything I can do to fix this problem?

我能做些什么来解决这个问题吗?

7 个解决方案

#1


5  

Early versions of the MySQL installer didn't set up the windows service at all. You might have to do it by hand.

早期版本的MySQL安装程序根本没有设置windows服务。你可能需要用手来做。

http://dev.mysql.com/doc/refman/5.1/en/windows-start-service.html

http://dev.mysql.com/doc/refman/5.1/en/windows-start-service.html

When the service is installed you should be able to enter the following command to start the service.

在安装服务时,您应该能够输入以下命令来启动服务。

net start mysql

Then all you need is to open a command window and type the following to get you into the MySQL command line where you can start writing your own queries.

然后,您所需要的就是打开一个命令窗口并输入以下命令,让您进入MySQL命令行,在那里您可以开始编写自己的查询。

mysql -uroot

I'm not terribly up on Microsoft SQL Server's flavour of SQL but I think that if you are used to using it then you might find it difficult to "get into" MySQL.

我不太喜欢微软SQL Server的SQL风格,但我认为如果你习惯使用它,那么你可能会发现很难进入MySQL。

Here's a simple tutorial that gives an overview of MySQL and creating queries. http://www.bigsoft.co.uk/blog/index.php/2012/10/04/sql-for-beginners

这里有一个简单的教程,概述MySQL和创建查询。http://www.bigsoft.co.uk/blog/index.php/2012/10/04/sql-for-beginners

#2


2  

  1. Check in Task Manager that mysql server is started.
  2. 检查mysql服务器启动的任务管理器。
  3. Check if you can connect to the server, run telnet <hostname> <portnumber>, e.g.:

    检查是否可以连接到服务器,运行telnet ,例如:

    telnet localhost 3306

    telnet localhost 3306

  4. If you could not connect, try to find server properties (check port number), also check your firewall.

    如果您无法连接,请尝试查找服务器属性(检查端口号),也检查您的防火墙。

#3


0  

Look for the file my.ini and add bind-address = 0.0.0.0 in the [mysqld] stanza.

找我的文件。在[mysqld] stanza中添加bind-address = 0.0.0.0。

#4


0  

Well, I don't exactly know what caused this issue in the first place, but I was able to find a way to solve it. A helpful, if old - perfect in this case - tutorial I found on the web, that hopefully can help others with the same problem.

我不知道是什么导致了这个问题,但是我找到了解决它的方法。在这个案例中,我发现了一个有用的,如果旧的完善的教程,希望可以帮助其他有同样问题的人。

Tutorial: Install MySQL 4.0 - Windows, by Dr. Thomas E. Hicks Computer Science Department Trinity University

教程:安装MySQL 4.0 - Windows,由Dr. Thomas E. Hicks计算机科学系三一大学。

Link Here

链接在这里

#5


0  

I'm not sure if the services application is on other windows or not but if you use Windows 7, you are lucky. The easiest method is to open Start panel,in the search box,type services and hit enter.Now scroll down till you find the mysql service.In the latest version, it is named MySQL57. Right click on it and click on start. Now you are good to use MySQL. However,you will have to perform this step every time the windows starts.

我不确定服务应用程序是否在其他窗口,但是如果你使用windows 7,你是幸运的。最简单的方法是打开启动面板,在搜索框中,键入服务并按回车键。现在向下滚动直到找到mysql服务。在最新版本中,它被命名为MySQL57。右键单击并单击start。现在可以使用MySQL了。但是,每次windows启动时,您都必须执行此步骤。

#6


0  

Open the MySQL Installer and click on where it says "reconfigure" next to "MySQL Server"

打开MySQL安装程序,然后点击“重新配置”到“MySQL服务器”。

#7


-1  

if it is showing error 2003 (HY000): Can't connect to MySQL server on localhost (10061) than 1.search services.msc in run 2.goto mysql properties 3.copy the mysql service name 4.start cmd as administrator 5.write: net start mysqlservicename .i.e mysql57 or etc it will show mysql is starting.

如果是显示错误2003 (HY000):无法连接到本地主机上的MySQL服务器(10061)。搜索服务。在运行2 msc。转到mysql属性3。复制mysql服务名4。作为管理员5启动cmd。写入:net启动mysqlservicename。它将显示mysql启动。

#1


5  

Early versions of the MySQL installer didn't set up the windows service at all. You might have to do it by hand.

早期版本的MySQL安装程序根本没有设置windows服务。你可能需要用手来做。

http://dev.mysql.com/doc/refman/5.1/en/windows-start-service.html

http://dev.mysql.com/doc/refman/5.1/en/windows-start-service.html

When the service is installed you should be able to enter the following command to start the service.

在安装服务时,您应该能够输入以下命令来启动服务。

net start mysql

Then all you need is to open a command window and type the following to get you into the MySQL command line where you can start writing your own queries.

然后,您所需要的就是打开一个命令窗口并输入以下命令,让您进入MySQL命令行,在那里您可以开始编写自己的查询。

mysql -uroot

I'm not terribly up on Microsoft SQL Server's flavour of SQL but I think that if you are used to using it then you might find it difficult to "get into" MySQL.

我不太喜欢微软SQL Server的SQL风格,但我认为如果你习惯使用它,那么你可能会发现很难进入MySQL。

Here's a simple tutorial that gives an overview of MySQL and creating queries. http://www.bigsoft.co.uk/blog/index.php/2012/10/04/sql-for-beginners

这里有一个简单的教程,概述MySQL和创建查询。http://www.bigsoft.co.uk/blog/index.php/2012/10/04/sql-for-beginners

#2


2  

  1. Check in Task Manager that mysql server is started.
  2. 检查mysql服务器启动的任务管理器。
  3. Check if you can connect to the server, run telnet <hostname> <portnumber>, e.g.:

    检查是否可以连接到服务器,运行telnet ,例如:

    telnet localhost 3306

    telnet localhost 3306

  4. If you could not connect, try to find server properties (check port number), also check your firewall.

    如果您无法连接,请尝试查找服务器属性(检查端口号),也检查您的防火墙。

#3


0  

Look for the file my.ini and add bind-address = 0.0.0.0 in the [mysqld] stanza.

找我的文件。在[mysqld] stanza中添加bind-address = 0.0.0.0。

#4


0  

Well, I don't exactly know what caused this issue in the first place, but I was able to find a way to solve it. A helpful, if old - perfect in this case - tutorial I found on the web, that hopefully can help others with the same problem.

我不知道是什么导致了这个问题,但是我找到了解决它的方法。在这个案例中,我发现了一个有用的,如果旧的完善的教程,希望可以帮助其他有同样问题的人。

Tutorial: Install MySQL 4.0 - Windows, by Dr. Thomas E. Hicks Computer Science Department Trinity University

教程:安装MySQL 4.0 - Windows,由Dr. Thomas E. Hicks计算机科学系三一大学。

Link Here

链接在这里

#5


0  

I'm not sure if the services application is on other windows or not but if you use Windows 7, you are lucky. The easiest method is to open Start panel,in the search box,type services and hit enter.Now scroll down till you find the mysql service.In the latest version, it is named MySQL57. Right click on it and click on start. Now you are good to use MySQL. However,you will have to perform this step every time the windows starts.

我不确定服务应用程序是否在其他窗口,但是如果你使用windows 7,你是幸运的。最简单的方法是打开启动面板,在搜索框中,键入服务并按回车键。现在向下滚动直到找到mysql服务。在最新版本中,它被命名为MySQL57。右键单击并单击start。现在可以使用MySQL了。但是,每次windows启动时,您都必须执行此步骤。

#6


0  

Open the MySQL Installer and click on where it says "reconfigure" next to "MySQL Server"

打开MySQL安装程序,然后点击“重新配置”到“MySQL服务器”。

#7


-1  

if it is showing error 2003 (HY000): Can't connect to MySQL server on localhost (10061) than 1.search services.msc in run 2.goto mysql properties 3.copy the mysql service name 4.start cmd as administrator 5.write: net start mysqlservicename .i.e mysql57 or etc it will show mysql is starting.

如果是显示错误2003 (HY000):无法连接到本地主机上的MySQL服务器(10061)。搜索服务。在运行2 msc。转到mysql属性3。复制mysql服务名4。作为管理员5启动cmd。写入:net启动mysqlservicename。它将显示mysql启动。