【问题标题】:ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/mysql/mysql.sock' - Missing files错误 2002 (HY000): 无法通过套接字 '/var/mysql/mysql.sock' 连接到本地 MySQL 服务器 - 缺少文件
【发布时间】:2015-03-09 01:45:05
【问题描述】:

我刚开始使用 Homebrew,我的 msql 正在运行。但我似乎无法登录。我已经重新启动了我的计算机,现在它没有运行。我跑了ps -u mysql 来确认这一点,它返回了UID PID TTY TIME CMD

在我加载的 php.ini 文件中,我的套接字命令看起来像这样

; Default socket name for local MySQL connects.  If empty, uses the built-in
; MySQL defaults.
; http://php.net/mysql.default-socket
mysql.default_socket =

在我的 my.cnf 文件中,我的套接字已关闭

# These are commonly set, remove the # and set as required.
# basedir = .....
# datadir = .....  
# port = .....
# server_id = .....
# socket = .....

在我的 homebrew 安装中 \var\mysql\ 我没有 mysql.sock 文件。

所以我想我的问题是我需要什么来解决这个问题?是创建一个mysql.sock文件(我不知道怎么做)然后在php.ini和my.cnf文件中填写空白或未注释的套接字引用的情况吗?

有很多关于无法在 S/O 上连接到 MYSQL 的问题。他们中的许多人从未得到答复。我查看了很多他们尝试自己解决问题的方法,但未能为比我聪明得多的人提供足够的(希望是相关的)信息来尝试解决问题。希望它是可修复的,其他人将从这个问题中受益。

更新

我已将 php.ini 和 my.cnf 中的套接字更新为 /tmp/mysql.sock。当我在我的 usr/local/var/mysql 文件夹中时,我可以看到我生成了一个 PID 文件。如果我运行mysqladmin version,我会得到Can't connect to local MySQL server through socket '/var/mysql/mysql.sock

这些是我的日志:

150110 23:53:39 mysqld_safe mysqld from pid file /usr/local/var/mysql/Jonnys-MacBook-Air.local.pid ended
150110 23:53:47 mysqld_safe Starting mysqld daemon with databases from /usr/local/var/mysql
2015-01-10 23:53:48 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2015-01-10 23:53:48 1660 [Warning] Setting lower_case_table_names=2 because file system for /usr/local/var/mysql/ is case insensitive
2015-01-10 23:53:48 1660 [Note] Plugin 'FEDERATED' is disabled.
2015-01-10 23:53:48 1660 [Note] InnoDB: Using atomics to ref count buffer pool pages
2015-01-10 23:53:48 1660 [Note] InnoDB: The InnoDB memory heap is disabled
2015-01-10 23:53:48 1660 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2015-01-10 23:53:48 1660 [Note] InnoDB: Memory barrier is not used
2015-01-10 23:53:48 1660 [Note] InnoDB: Compressed tables use zlib 1.2.3
2015-01-10 23:53:48 1660 [Note] InnoDB: Using CPU crc32 instructions
2015-01-10 23:53:48 1660 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2015-01-10 23:53:48 1660 [Note] InnoDB: Completed initialization of buffer pool
2015-01-10 23:53:48 1660 [Note] InnoDB: Highest supported file format is Barracuda.
2015-01-10 23:53:48 1660 [Note] InnoDB: 128 rollback segment(s) are active.
2015-01-10 23:53:48 1660 [Note] InnoDB: Waiting for purge to start
2015-01-10 23:53:48 1660 [Note] InnoDB: 5.6.22 started; log sequence number 1637555
2015-01-10 23:53:48 1660 [Note] RSA private key file not found: /usr/local/var/mysql//private_key.pem. Some authentication plugins will not work.
2015-01-10 23:53:48 1660 [Note] RSA public key file not found: /usr/local/var/mysql//public_key.pem. Some authentication plugins will not work.
2015-01-10 23:53:48 1660 [Note] Server hostname (bind-address): '127.0.0.1'; port: 3306
2015-01-10 23:53:48 1660 [Note]   - '127.0.0.1' resolves to '127.0.0.1';
2015-01-10 23:53:48 1660 [Note] Server socket created on IP: '127.0.0.1'.
2015-01-10 23:53:48 1660 [Note] Event Scheduler: Loaded 0 events
2015-01-10 23:53:48 1660 [Note] /usr/local/Cellar/mysql/5.6.22/bin/mysqld: ready for connections.
Version: '5.6.22'  socket: '/tmp/mysql.sock'  port: 3306  Homebrew
2015-01-10 23:54:43 1660 [Note] /usr/local/Cellar/mysql/5.6.22/bin/mysqld: Normal shutdown

2015-01-10 23:54:43 1660 [Note] Giving 0 client threads a chance to die gracefully
2015-01-10 23:54:43 1660 [Note] Event Scheduler: Purging the queue. 0 events
2015-01-10 23:54:43 1660 [Note] Shutting down slave threads
2015-01-10 23:54:43 1660 [Note] Forcefully disconnecting 0 remaining clients
2015-01-10 23:54:43 1660 [Note] Binlog end
2015-01-10 23:54:43 1660 [Note] Shutting down plugin 'partition'
2015-01-10 23:54:43 1660 [Note] Shutting down plugin 'PERFORMANCE_SCHEMA'
2015-01-10 23:54:43 1660 [Note] Shutting down plugin 'INNODB_SYS_DATAFILES'
2015-01-10 23:54:43 1660 [Note] Shutting down plugin 'INNODB_SYS_TABLESPACES'
2015-01-10 23:54:43 1660 [Note] Shutting down plugin 'INNODB_SYS_FOREIGN_COLS'
2015-01-10 23:54:43 1660 [Note] Shutting down plugin 'INNODB_SYS_FOREIGN'
2015-01-10 23:54:43 1660 [Note] Shutting down plugin 'INNODB_SYS_FIELDS'
2015-01-10 23:54:43 1660 [Note] Shutting down plugin 'INNODB_SYS_COLUMNS'
2015-01-10 23:54:43 1660 [Note] Shutting down plugin 'INNODB_SYS_INDEXES'
2015-01-10 23:54:43 1660 [Note] Shutting down plugin 'INNODB_SYS_TABLESTATS'
2015-01-10 23:54:43 1660 [Note] Shutting down plugin 'INNODB_SYS_TABLES'
2015-01-10 23:54:43 1660 [Note] Shutting down plugin 'INNODB_FT_INDEX_TABLE'
2015-01-10 23:54:43 1660 [Note] Shutting down plugin 'INNODB_FT_INDEX_CACHE'
2015-01-10 23:54:43 1660 [Note] Shutting down plugin 'INNODB_FT_CONFIG'
2015-01-10 23:54:43 1660 [Note] Shutting down plugin 'INNODB_FT_BEING_DELETED'
2015-01-10 23:54:43 1660 [Note] Shutting down plugin 'INNODB_FT_DELETED'
2015-01-10 23:54:43 1660 [Note] Shutting down plugin 'INNODB_FT_DEFAULT_STOPWORD'
2015-01-10 23:54:43 1660 [Note] Shutting down plugin 'INNODB_METRICS'
2015-01-10 23:54:43 1660 [Note] Shutting down plugin 'INNODB_BUFFER_POOL_STATS'
2015-01-10 23:54:43 1660 [Note] Shutting down plugin 'INNODB_BUFFER_PAGE_LRU'
2015-01-10 23:54:43 1660 [Note] Shutting down plugin 'INNODB_BUFFER_PAGE'
2015-01-10 23:54:43 1660 [Note] Shutting down plugin 'INNODB_CMP_PER_INDEX_RESET'
2015-01-10 23:54:43 1660 [Note] Shutting down plugin 'INNODB_CMP_PER_INDEX'
2015-01-10 23:54:43 1660 [Note] Shutting down plugin 'INNODB_CMPMEM_RESET'
2015-01-10 23:54:43 1660 [Note] Shutting down plugin 'INNODB_CMPMEM'
2015-01-10 23:54:43 1660 [Note] Shutting down plugin 'INNODB_CMP_RESET'
2015-01-10 23:54:43 1660 [Note] Shutting down plugin 'INNODB_CMP'
2015-01-10 23:54:43 1660 [Note] Shutting down plugin 'INNODB_LOCK_WAITS'
2015-01-10 23:54:43 1660 [Note] Shutting down plugin 'INNODB_LOCKS'
2015-01-10 23:54:43 1660 [Note] Shutting down plugin 'INNODB_TRX'
2015-01-10 23:54:43 1660 [Note] Shutting down plugin 'InnoDB'
2015-01-10 23:54:43 1660 [Note] InnoDB: FTS optimize thread exiting.
2015-01-10 23:54:43 1660 [Note] InnoDB: Starting shutdown...
2015-01-10 23:54:44 1660 [Note] InnoDB: Shutdown completed; log sequence number 1637565
2015-01-10 23:54:44 1660 [Note] Shutting down plugin 'BLACKHOLE'
2015-01-10 23:54:44 1660 [Note] Shutting down plugin 'ARCHIVE'
2015-01-10 23:54:44 1660 [Note] Shutting down plugin 'MRG_MYISAM'
2015-01-10 23:54:44 1660 [Note] Shutting down plugin 'MyISAM'
2015-01-10 23:54:44 1660 [Note] Shutting down plugin 'MEMORY'
2015-01-10 23:54:44 1660 [Note] Shutting down plugin 'CSV'
2015-01-10 23:54:44 1660 [Note] Shutting down plugin 'sha256_password'
2015-01-10 23:54:44 1660 [Note] Shutting down plugin 'mysql_old_password'
2015-01-10 23:54:44 1660 [Note] Shutting down plugin 'mysql_native_password'
2015-01-10 23:54:44 1660 [Note] Shutting down plugin 'binlog'
2015-01-10 23:54:44 1660 [Note] /usr/local/Cellar/mysql/5.6.22/bin/mysqld: Shutdown complete

150110 23:55:16 mysqld_safe Starting mysqld daemon with databases from /usr/local/var/mysql
2015-01-10 23:55:17 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2015-01-10 23:55:17 462 [Warning] Setting lower_case_table_names=2 because file system for /usr/local/var/mysql/ is case insensitive
2015-01-10 23:55:17 462 [Note] Plugin 'FEDERATED' is disabled.
2015-01-10 23:55:17 462 [Note] InnoDB: Using atomics to ref count buffer pool pages
2015-01-10 23:55:17 462 [Note] InnoDB: The InnoDB memory heap is disabled
2015-01-10 23:55:17 462 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2015-01-10 23:55:17 462 [Note] InnoDB: Memory barrier is not used
2015-01-10 23:55:17 462 [Note] InnoDB: Compressed tables use zlib 1.2.3
2015-01-10 23:55:17 462 [Note] InnoDB: Using CPU crc32 instructions
2015-01-10 23:55:17 462 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2015-01-10 23:55:17 462 [Note] InnoDB: Completed initialization of buffer pool
2015-01-10 23:55:17 462 [Note] InnoDB: Highest supported file format is Barracuda.
2015-01-10 23:55:17 462 [Note] InnoDB: 128 rollback segment(s) are active.
2015-01-10 23:55:17 462 [Note] InnoDB: Waiting for purge to start
2015-01-10 23:55:17 462 [Note] InnoDB: 5.6.22 started; log sequence number 1637565
2015-01-10 23:55:17 462 [Note] RSA private key file not found: /usr/local/var/mysql//private_key.pem. Some authentication plugins will not work.
2015-01-10 23:55:17 462 [Note] RSA public key file not found: /usr/local/var/mysql//public_key.pem. Some authentication plugins will not work.
2015-01-10 23:55:17 462 [Note] Server hostname (bind-address): '127.0.0.1'; port: 3306
2015-01-10 23:55:17 462 [Note]   - '127.0.0.1' resolves to '127.0.0.1';
2015-01-10 23:55:17 462 [Note] Server socket created on IP: '127.0.0.1'.
2015-01-10 23:55:18 462 [Note] Event Scheduler: Loaded 0 events
2015-01-10 23:55:18 462 [Note] /usr/local/Cellar/mysql/5.6.22/bin/mysqld: ready for connections.
Version: '5.6.22'  socket: '/tmp/mysql.sock'  port: 3306  Homebrew

【问题讨论】:

    标签: mysql sockets homebrew


    【解决方案1】:

    你有这个文件吗?

    /tmp/mysql.sock
    

    如果是这样,请尝试将其添加到您的 php.ini 中

    mysql.default_socket = /tmp/mysql.sock
    

    然后重启apache

    sudo apachectl restart
    

    否则你有问题,你应该尝试重新启动你的 mysqld 服务:

    launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
    

    【讨论】:

    • 我好像没有那个文件。我的 /usr/local/ 文件夹中没有 tmp 文件夹
    • 我跑了mysql_config --socket,它回来了/tmp/mysql.sock。所以我更新了我的php.ini 文件。重新启动阿帕奇。我运行了最后一个命令,它说操作已经在进行中。
    猜你喜欢
    • 2019-01-26
    • 2014-11-27
    • 2013-03-05
    • 2013-11-08
    • 2012-10-14
    • 2014-03-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多