无法使用 root 用户在 localhost:3306 连接到 MySQL

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/32022580/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 21:12:43  来源:igfitidea点击:

Failed to Connect to MySQL at localhost:3306 with user root

mysql

提问by shengfu zou

I use Mysql Workbench to connect my database,[Hostname Port and Username are as shown in figure ,and password is right[1]

我使用 Mysql Workbench 连接我的数据库,[Hostname Port和Username如图,密码正确[1]

Hostname Port and Username are as shown in figure ,and password is right.When I click Test Connection ,it show as above.But if i use 3307 in place of 3306 as port,it connect sucessfully. What matter lead that and how I fix it?

主机名端口和用户名如图,密码正确。当我点击测试连接时,显示如上。但如果我使用3307代替3306作为端口,则连接成功。什么问题导致了它以及我如何解决它?

I use macbook pro and I don't know check which my.cnf. I use sudo vim /usr/local/mysql/my.cnf in terminal .
And the my.cnf is as below:

我用的是macbook pro,不知道查哪个my.cnf。我在终端中使用 sudo vim /usr/local/mysql/my.cnf 。
而 my.cnf 如下:

[mysqld] 
 sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES            

And I rewite it as below:

我将其重写如下:

[client]
port=3306
socket=/tmp/mysql.sock

[mysqld]
port=3306
socket=/tmp/mysql.sock
key_buffer_size=16M
max_allowed_packet=8M 
[mysqldump]
quick 

But it does not work.

但它不起作用。

回答by Abhishek Singh

Steps:

脚步:

1 - Right clickon your task bar -->Start Task Manager

1 -右键单击任务栏 -->启动任务管理器

2 - Clickon Servicesbutton (at bottom).

2 -点击服务按钮(在底部)。

3 - Search for MYSQL57

3 - 搜索MYSQL57

4 - Right Clickon MYSQL57 --> Start

4 -右键单击MYSQL57 -->开始

Now again startyour mysql-cmd-promptor MYSQL WorkBench

现在再次启动您的mysql-cmd-promptMYSQL WorkBench

回答by Hau Le

Open System Preference > MySQL > Initialize Database > Use Legacy Password Encription

打开“系统偏好设置”>“MySQL”>“初始化数据库”>“使用旧密码加密”

回答by Darshan Patel

Try to execute below command in your terminal :

尝试在终端中执行以下命令:

mysql -h localhost -P 3306 -u root -p

If you successfully connect to your database, then same thing has to happen with Mysql Workbench.

如果你成功连接到你的数据库,那么同样的事情必须发生在Mysql Workbench.

If you are unable to connect then I think 3306port is acquired by another process.

如果您无法连接,那么我认为3306端口已被另一个进程获取。

Find which process running on 3306port. If required, give admin privileges using sudo.

查找在3306端口上运行的进程。如果需要,请使用sudo.

netstat -lnp | grep 3306

Kill/stop that process and restart your MySQL server. You are good to go.

终止/停止该进程并重新启动您的 MySQL 服务器。你已准备好出发。



Execute below command to find my.cnffile in macbook.

执行以下命令my.cnf在 macbook 中查找文件。

mysql --help | grep cnf

You can change MySQLport to any available port in your system. But after that, make sure you restart MySQLserver.

您可以将MySQL端口更改为系统中的任何可用端口。但在那之后,请确保重新启动MySQL服务器。

回答by Ronald Milligan

Go to >system preferences >mysql >initialize database

转到 > 系统首选项 > mysql > 初始化数据库

-Change password -Click use legacy password -Click start sql server

-更改密码 -单击使用旧密码 -单击启动 sql server

it should work now

现在应该可以使用了

回答by almawhoob

Go to system preferences, then "MySQL"

转到系统首选项,然后“MySQL”

Click on "Start MySQL Server"

单击“启动 MySQL 服务器”

Go to system preferences, then "MySQL". Click on "Start MySQL Server".

转到系统首选项,然后是“MySQL”。单击“启动 MySQL 服务器”。

回答by Yan Xu

  1. go to apple icon on the top left corn and click "System Preference"

  2. find "Mysql" at the bottom and click it

  3. "start Mysql server"

  1. 转到左上角的苹果图标,然后单击“系统偏好设置”

  2. 在底部找到“Mysql”并单击它

  3. “启动Mysql服务器”

回答by Hymanie Santana

It failed because there is no server install on your computer. You need to Download 'MySQL Community Server 8.0.17' & restart your server.

它失败了,因为您的计算机上没有安装服务器。您需要下载“MySQL Community Server 8.0.17”并重新启动您的服务器。

回答by Tobia John

At rigth side in Navigator -> Instance-> Click on Startup/Shutdown -> Click on Start Server

在导航器右侧 -> 实例 -> 单击启动/关闭 -> 单击启动服务器

It will work surely

它肯定会起作用

回答by J0ker98

MySQL default port is 3306 but it may be unavailable for some reasons, try to restart your machine. Also sesrch for your MySQL configuration file (should be called "my.cnf") and check if the used port is 3306 or 3307, if is 3307 you can change it to 3306 and then reboot your MySQL server.

MySQL 默认端口是 3306 但由于某些原因它可能不可用,请尝试重新启动机器。还要搜索你的 MySQL 配置文件(应该叫“my.cnf”)并检查使用的端口是 3306 还是 3307,如果是 3307 你可以把它改成 3306 然后重启你的 MySQL 服务器。