MacOS Catalina错误2002(HY000):无法通过套接字'/tmp/mysql.sock'连接到本地MySQL服务器(2)

时间:2020-04-28 06:55:29

标签: mysql macos mariadb homebrew macos-catalina

我试图通过Google搜索解决此错误,但无法解决。

我在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,我该如何解决?

我错过了什么吗?

请让我知道是否应该提供更多信息。

谢谢!

1 个答案:

答案 0 :(得分:1)

我认为发生此问题是因为我之前通过mysql安装了brew并将其删除:

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插件。如果有人知道并且可以解释,那就太好了。

相关问题