簡體   English   中英

錯誤 2002 (HY000): 無法通過 OSX 中的套接字 '/tmp/mysql.sock' (2) 連接到本地 MySQL 服務器

[英]ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) in OSX

我正在嘗試使用我在 XAMPP conf 文件中的用戶密碼登錄 mysql,但是我收到以下錯誤:

mysql -u mysql -p;                                                                                                                            1 ✘  at 11:48:02 AM 
Enter password: 
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

我在下面的conf文件/Applications/XAMPP/xamppfiles/etc/my.cnf中輸入了1234作為密碼:

# The following options will be passed to all MySQL clients
[client]
password        =1234
port            =3306
socket          =/Applications/XAMPP/xamppfiles/var/mysql/mysql.sock

# Here follows entries for some specific programs

# The MySQL server
default-character-set=utf8mb4
[mysqld]
user=mysql
port=3306
socket          =/Applications/XAMPP/xamppfiles/var/mysql/mysql.sock
key_buffer=16M
max_allowed_packet=1M
table_open_cache=64
sort_buffer_size=512K
net_buffer_length=8K
read_buffer_size=256K
read_rnd_buffer_size=512K
myisam_sort_buffer_size=8M

此外,這是運行 mysql 守護進程的信息:

ps aux | grep mysql                                                                                                                      PIPE|2 ✘  at 11:55:38 AM 
mona              6189   0.0  0.0  4286736    724 s003  S+   11:56AM   0:00.00 grep --color=auto --exclude-dir=.bzr --exclude-dir=CVS --exclude-dir=.git --exclude-dir=.hg --exclude-dir=.svn --exclude-dir=.idea --exclude-dir=.tox mysql
_mysql            5707   0.0  0.0  4589008   8172   ??  S    11:53AM   0:00.10 /Applications/XAMPP/xamppfiles/sbin/mysqld --basedir=/Applications/XAMPP/xamppfiles --datadir=/Applications/XAMPP/xamppfiles/var/mysql --plugin-dir=/Applications/XAMPP/xamppfiles/lib/mysql/plugin/ --log-error=/Applications/XAMPP/xamppfiles/var/mysql/goku.err --pid-file=/Applications/XAMPP/xamppfiles/var/mysql/goku.pid --socket=/Applications/XAMPP/xamppfiles/var/mysql/mysql.sock --port=3306
root              5555   0.0  0.0  4308708    844   ??  S    11:53AM   0:00.02 /bin/sh /Applications/XAMPP/xamppfiles/bin/mysqld_safe --datadir=/Applications/XAMPP/xamppfiles/var/mysql --pid-file=/Applications/XAMPP/xamppfiles/var/mysql/goku.pid

這是我在 XAMPP 中看到的:

在此處輸入圖像描述

我有 OSX Catalina 10.15.7 (19H1713)。

在取消注釋密碼並將其設置為1234后,我停止並在 XAMPP UI 中啟動了 mySQL,但仍然無法登錄。

我輸入如下,但仍然沒有進入 mysql shell: mysql -u mysql -h 127.0.0.1 -port 3306 -p 1234;

我看到類似的東西:

mysql: [Warning] Using a password on the command line interface can be insecure.
/usr/local/mysql/bin/mysql  Ver 8.0.29 for macos12 on x86_64 (MySQL Community Server - GPL)
Copyright (c) 2000, 2022, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Usage: /usr/local/mysql/bin/mysql [OPTIONS] [database]
  -?, --help          Display this help and exit.
  -I, --help          Synonym for -?
  --auto-rehash       Enable automatic rehashing. One doesn't need to use
                      'rehash' to get table and field completion, but startup
                      and reconnecting may take a longer time. Disable with
                      --disable-auto-rehash.
                      (Defaults to on; use --skip-auto-rehash to disable.)

不傳遞端口信息(因為 3306 是默認端口),我收到此錯誤,盡管1234是我在 xampp 的 mysql conf 文件中設置的密碼):

mysql -u mysql  -h 127.0.0.1 -p;                                                                                                              1 ✘  at 12:29:02 PM 
Enter password: 
ERROR 1045 (28000): Access denied for user 'mysql'@'localhost' (using password: YES)
mysql -u root  -h 127.0.0.1 -p;                                                                                                               1 ✘  at 12:34:13 PM 
Enter password:

當它要求輸入密碼時,按回車,你現在在 mysql shell 中。 您可以在此處查看現有用戶列表:


mysql> SELECT user FROM mysql.user;
+------+
| user |
+------+
| root |
| root |
|      |
| pma  |
| root |
+------+

現在,創建一個用戶並為其設置密碼,例如:

mysql> CREATE USER 'mona'@'localhost' IDENTIFIED BY '1234';
Query OK, 0 rows affected (0.01 sec)

mysql> SELECT user FROM mysql.user;
+------+
| user |
+------+
| root |
| root |
|      |
| mona |
| pma  |
| root |
+------+
6 rows in set (0.00 sec)

現在退出mysql shell,在提示符前輸入以下命令:

mysql -u mona -h 127.0.0.1 -p; 和密碼輸入1234

您現在進入用戶mona的 mysql shell。

有關更多信息,請查看本教程

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM