无法在 Mac 上的“127.0.0.1”(61) 上连接到 MySQL 服务器

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/32295276/
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:14:59  来源:igfitidea点击:

Can't connect to MySQL server on '127.0.0.1' (61) on Mac

mysqlmacosmysql-workbench

提问by Kyuu

Having some trouble creating a mysql connection. The mysql instance is running in system preferences and I have made sure the mysql config file is in the right location(Test settings passed). When I go into Test DB connections I get red cross on all three sections.(open database connections, get server version, get server OS). Running mac 10.10.2. Set connection name as home hostname as 127.0.0.1, port as 3306, username as root, password as my computers root password and default schema as home as well. Any ideas?

创建 mysql 连接时遇到一些麻烦。mysql 实例正在系统首选项中运行,我已确保 mysql 配置文件位于正确的位置(测试设置已通过)。当我进入测试数据库连接时,我在所有三个部分都得到红叉。(打开数据库连接,获取服务器版本,获取服务器操作系统)。运行 mac 10.10.2。将连接名称设置为 home 主机名 127.0.0.1,端口设置为 3306,用户名设置为 root,密码设置为我的计算机 root 密码,默认架构设置为 home。有任何想法吗?

回答by Golam Sorwar

enter image description here

在此处输入图片说明

You can see this type of error , try this:

你可以看到这种类型的错误,试试这个:

run this command on your iTerm or Terminal:

在您的 iTerm 或终端上运行此命令:

sudo mysql.server start

If you see some errors like this:

如果你看到一些这样的错误:

my_print_defaults: Can't read dir of '/usr/local/etc/my.cnf.d' (OS errno 2 - No such file or directory)

my_print_defaults: [ERROR] Fatal error in defaults handling. Program aborted!
Starting MySQL

.my_print_defaults: Can't read dir of '/usr/local/etc/my.cnf.d' (OS errno 2 - No such file or directory)

my_print_defaults: [ERROR] Fatal error in defaults handling. Program aborted!

my_print_defaults: Can't read dir of '/usr/local/etc/my.cnf.d' (OS errno 2 - No such file or directory)

my_print_defaults: [ERROR] Fatal error in defaults handling. Program aborted!
 ERROR! The server quit without updating PID file (/usr/local/var/mysql/MacBook-Pro.local.pid).

Just make the dir:

只需制作目录:

mkdir /usr/local/etc/my.cnf.d

and then run it again:

然后再次运行它:

sudo mysql.server start

Works for me.

为我工作。

回答by Engr.Tanbir Hasan

  1. Delete pid files using this command:

    $ cd /usr/local/var/mysql
    $ sudo rm -rf [networkname*].err
    $ sudo rm -rf [networkname*].pid
    
    1. Now restart server use brewsevices

    $ brew services restart mysql

  1. 使用以下命令删除 pid 文件:

    $ cd /usr/local/var/mysql
    $ sudo rm -rf [networkname*].err
    $ sudo rm -rf [networkname*].pid
    
    1. 现在重新启动服务器使用brew服务

    $ brew services restart mysql

∗your network name like "Tanbirs-Mac-mini.local" (use echo $HOST)

∗您的网络名称如“Tanbirs-Mac-mini.local”(使用echo $HOST

回答by Java Basketball

Today i have come with this issue, i solved it using the following steps:

今天我遇到了这个问题,我使用以下步骤解决了它:

First, check whether listening to the port 3306:

首先检查是否监听3306端口:

netstat -tulpen

if it prints the following log, it would be right:

如果它打印以下日志,那就对了:

...
tcp6 0 0 :::3306 :::* LISTEN 27 46396 22054/mysqld
...

otherwise, edit the file my.cnfand add the code to it:

否则,编辑文件my.cnf并向其中添加代码:

bind-address = 0.0.0.0

it means that it listens to all ports.

这意味着它侦听所有端口。

Secondly, in the CentOS 7 add the Mysql service to firewall:

其次,在 CentOS 7 中添加 Mysql 服务到防火墙:

sudo firewall-cmd --zone=public --permanent --add-service=mysql

it returns Success, and then going on executing the command:

它返回成功,然后继续执行命令:

sudo systemctl restart firewalld

Now, it's OK!!!

现在可以了!!!

回答by Marcos QP

I had same problem, but it worked for me.

我有同样的问题,但它对我有用。

  1. check if you have mysql installed

    enter image description here

  1. 检查你是否安装了mysql

    在此处输入图片说明

If you don't have mysql installed, download from this link: https://dev.mysql.com/downloads/mysql/

如果您没有安装 mysql,请从此链接下载:https: //dev.mysql.com/downloads/mysql/

  1. follow this instructions to install https://dev.mysql.com/doc/mysql-osx-excerpt/5.7/en/osx-installation-pkg.html

  2. You can test the connection without any problem.

  1. 按照此说明安装 https://dev.mysql.com/doc/mysql-osx-excerpt/5.7/en/osx-installation-pkg.html

  2. 您可以毫无问题地测试连接。

(Sorry for my english, I agree fix me please)

(对不起,我的英语,我同意请修复我)

I Hope I've helped. Greetings.

我希望我有所帮助。你好。