Mysql.sock 缺失-“无法通过套接字连接到本地 MySQL 服务器”

Mysql.sock 缺失-“无法通过套接字连接到本地 MySQL 服务器”

我正在关注指南,在 PC 上使用 XAMPP 设置 WordPress,在 Mac(macOS 10.11.2)上使用 MAMP(3.5),其中我在步骤“Mac - 4”被要求输入:

“在终端运行:/Applications/MAMP/Library/bin/mysqladmin -u root -p password {此处输入您的 Windows MySQL 密码}”

但是,这(不带括号文本)会导致错误消息:

error: 'Can't connect to local MySQL server through socket '/Applications/MAMP/tmp/mysql/mysql.sock' (2)'
Check that mysqld is running and that the socket: '/Applications/MAMP/tmp/mysql/mysql.sock' exists!

查看给定的目录,没有 mysql.sock 文件。

尝试启动 MAMP(不配置 mysqladmin)会导致错误日志:

160113 20:42:10 mysqld_safe Starting mysqld daemon with databases from /Applications/MAMP/db/mysql
160113 20:42:10 [Warning] Setting lower_case_table_names=2 because file system for /Applications/MAMP/db/mysql/ is case insensitive
160113 20:42:10 [Note] Plugin 'FEDERATED' is disabled.
160113 20:42:10 InnoDB: The InnoDB memory heap is disabled
160113 20:42:10 InnoDB: Mutexes and rw_locks use GCC atomic builtins
160113 20:42:10 InnoDB: Compressed tables use zlib 1.2.3
160113 20:42:10 InnoDB: Initializing buffer pool, size = 128.0M
160113 20:42:10 InnoDB: Completed initialization of buffer pool
160113 20:42:10 InnoDB: highest supported file format is Barracuda.
InnoDB: The log sequence number in ibdata files does not match
InnoDB: the log sequence number in the ib_logfiles!
160113 20:42:10  InnoDB: Database was not shut down normally!
InnoDB: Starting crash recovery.
InnoDB: Reading tablespace information from the .ibd files...
InnoDB: Restoring possible half-written data pages from the doublewrite
InnoDB: buffer...
160113 20:42:10  InnoDB: Waiting for the background threads to start
160113 20:42:11 InnoDB: 5.5.42 started; log sequence number 139375528
160113 20:42:11  InnoDB: Warning: table 'wordpress/wp_posts'
InnoDB: in InnoDB data dictionary has unknown flags 50.
160113 20:42:11 [Note] Server hostname (bind-address): '0.0.0.0'; port: 3306
160113 20:42:11  InnoDB: Warning: table 'wordpress/wp_postm160113 20:42:11 [Note]   - '0.0.0.0' resolves to '0.0.0.0';
eta'
InnoDB: in InnoDB data dictionary has unknown flags 50.
160113 20:42:11 [Note] Server socket created on IP: '0.0.0.0'.
160113 20:42:11 [ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.host' doesn't exist
160113 20:42:11 mysqld_safe mysqld from pid file /Applications/MAMP/tmp/mysql/mysql.pid ended

答案1

根据MySQL 安装疑难解答参考手册(这是针对Windows的,但是对于其他系统应该也是一样的),错误:

致命错误:无法打开特权表:表“mysql.host”不存在

当 MySQL 基础目录或数据目录安装在不同位置时,可能会发生这种情况。当您升级并安装到新位置,但使用旧配置文件时,可能会发生这种情况。如果是这种情况,请确保在升级 MySQL 时重命名所有旧配置文件。

否则,请编辑您的my.ini并仔细检查basedirdatadir(在[mysqld]部分中)是否指向正确的位置。

如果它们正确,请尝试使用以下命令重新创建 MySQL 核心结构:

sudo mysql_install_db –-user=mysql –ldata=/YOUR/datadir

如果以上方法没有帮助,请从头开始重新安装您的 MAMP/mysql。

相关内容