【问题标题】:MacOS Catalina ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)MacOS Catalina ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
【发布时间】:2020-08-11 22:07:49
【问题描述】:

我尝试通过谷歌搜索解决此错误,但无法解决。

我在 Mac OS Catalina 10.15.4 上。

我使用 HomeBrew 安装了 MariaDB,但无法使用 mysql 命令。

以下是我运行的命令和输出:


$ brew install mariadb
==> Downloading https://homebrew.bintray.com/bottles/mariadb-10.4.12.catalina.bottle.tar.gz
Already downloaded: /Users/a1646259/Library/Caches/Homebrew/downloads/3072e5af25f87508635402d401c601f32002e8ab956a37a9fd50f5656a2ffb80--mariadb-10.4.12.catalina.bottle.tar.gz
==> Pouring mariadb-10.4.12.catalina.bottle.tar.gz
==> /usr/local/Cellar/mariadb/10.4.12/bin/mysql_install_db --verbose --user=a1646259 --basedir=/usr/local/Cellar/mariadb/10.4.12 --datadir=/usr/local/var/mys
Last 15 lines from /Users/a1646259/Library/Logs/Homebrew/mariadb/post_install.01.mysql_install_db:

    shell> /usr/local/Cellar/mariadb/10.4.12/bin/mysql -u root mysql
    mysql> show tables;

Try 'mysqld --help' if you have problems with paths.  Using
--general-log gives you a log in /usr/local/var/mysql that may be helpful.

The latest information about mysql_install_db is available at
https://mariadb.com/kb/en/installing-system-tables-mysql_install_db
You can find the latest source at https://downloads.mariadb.org and
the maria-discuss email list at https://launchpad.net/~maria-discuss

Please check all of the above before submitting a bug report
at http://mariadb.org/jira

Warning: The post-install step did not complete successfully
You can try again using `brew postinstall mariadb`
==> Caveats
A "/etc/my.cnf" from another install may interfere with a Homebrew-built
server starting up correctly.

MySQL is configured to only allow connections from localhost by default

To have launchd start mariadb now and restart at login:
  brew services start mariadb
Or, if you don't want/need a background service you can just run:
  mysql.server start
==> Summary
????  /usr/local/Cellar/mariadb/10.4.12: 743 files, 168.2MB

$ mysql
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

$   mysql.server start
Starting MariaDB
200428 16:18:14 mysqld_safe Logging to '/usr/local/var/mysql/YU-CHIEHs-MacBook-Pro.local.err'.
200428 16:18:14 mysqld_safe Starting mysqld daemon with databases from /usr/local/var/mysql
.../usr/local/bin/mysql.server: line 264: kill: (34819) - No such process
 ERROR!

$ mysql
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

$   brew services start mariadb
Service `mariadb` already started, use `brew services restart mariadb` to restart.

$ mysql
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

$ brew services restart mariadb
Stopping `mariadb`... (might take a while)
==> Successfully stopped `mariadb` (label: homebrew.mxcl.mariadb)
==> Successfully started `mariadb` (label: homebrew.mxcl.mariadb)

$ mysql
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

$ mysqld
2020-04-28 16:18:51 0 [Note] mysqld (mysqld 10.4.12-MariaDB) starting as process 35672 ...
2020-04-28 16:18:51 0 [Warning] Setting lower_case_table_names=2 because file system for /usr/local/var/mysql/ is case insensitive
2020-04-28 16:18:51 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2020-04-28 16:18:51 0 [Note] InnoDB: Uses event mutexes
2020-04-28 16:18:51 0 [Note] InnoDB: Compressed tables use zlib 1.2.11
2020-04-28 16:18:51 0 [Note] InnoDB: Number of pools: 1
2020-04-28 16:18:51 0 [Note] InnoDB: Using SSE2 crc32 instructions
2020-04-28 16:18:51 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M
2020-04-28 16:18:51 0 [Note] InnoDB: Completed initialization of buffer pool
2020-04-28 16:18:51 0 [Note] InnoDB: 128 out of 128 rollback segments are active.
2020-04-28 16:18:51 0 [Note] InnoDB: Creating shared tablespace for temporary tables
2020-04-28 16:18:51 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
2020-04-28 16:18:51 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
2020-04-28 16:18:51 0 [Note] InnoDB: Waiting for purge to start
2020-04-28 16:18:51 0 [Note] InnoDB: 10.4.12 started; log sequence number 47136; transaction id 9
2020-04-28 16:18:51 0 [Note] InnoDB: Loading buffer pool(s) from /usr/local/var/mysql/ib_buffer_pool
2020-04-28 16:18:51 0 [Note] Plugin 'FEEDBACK' is disabled.
2020-04-28 16:18:51 0 [ERROR] Could not open mysql.plugin table. Some plugins may be not loaded
2020-04-28 16:18:51 0 [ERROR] mysqld: unknown variable 'mysqlx-bind-address=127.0.0.1'
2020-04-28 16:18:51 0 [ERROR] Aborting
2020-04-28 16:18:51 0 [Note] InnoDB: Buffer pool(s) load completed at 200428 16:18:51

$ mysql
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

$ brew services restart mariadb
Stopping `mariadb`... (might take a while)
==> Successfully stopped `mariadb` (label: homebrew.mxcl.mariadb)
==> Successfully started `mariadb` (label: homebrew.mxcl.mariadb)

$ mysql
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

$ ls /etc/my.cnf
ls: /etc/my.cnf: No such file or directory

$

为什么我不能使用 mariadb,我该如何解决这个问题?

我错过了什么吗?

如果我应该提供更多信息,请告诉我。

谢谢!

【问题讨论】:

    标签: mysql macos mariadb homebrew macos-catalina


    【解决方案1】:

    我认为这个问题的发生是因为我之前通过brew 安装了mysql 并删除了它:

    brew install mysql
    brew uninstall mysql
    

    使用 brew 安装 mysql 会创建这个 /usr/local/etc/my.cnf 文件:

    # Default Homebrew MySQL server config
    [mysqld]
    # Only allow connections from localhost
    bind-address = 127.0.0.1
    mysqlx-bind-address = 127.0.0.1
    

    安装 MariaDB 并使用它:

    rm /usr/local/etc/my.cnf
    brew uninstall mariadb
    ps -ax | grep mysql
    # and kill running mysql processes found above
    brew install mariadb
    mysql # should work now
    

    现在,如果您再次检查/usr/local/etc/my.cnf,您会看到:

    #
    # This group is read both both by the client and the server
    # use it for options that affect everything
    #
    [client-server]
    
    #
    # include all files from the config directory
    #
    !includedir /usr/local/etc/my.cnf.d
    

    这似乎是 MariaDB 应该使用的正确方法。

    经过一番调查,似乎这条线导致了所有这些问题:

    mysqlx-bind-address = 127.0.0.1
    

    根据MySQL's documentation about X Plugin,它似乎试图在启用 X 插件时只允许从本地主机访问。

    我不知道为什么会出现这个问题,可能是因为我的电脑没有安装 X Plugin。如果有人知道并可以解释,那就太好了。

    【讨论】:

    • 我仍然遇到同样的错误 ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
    猜你喜欢
    • 2014-10-16
    • 2013-10-06
    • 2021-03-31
    • 2023-03-20
    • 1970-01-01
    • 2018-05-15
    • 2021-05-04
    • 2017-05-03
    • 1970-01-01
    相关资源
    最近更新 更多