无法通过套接字“/opt/local/var/run/percona/mysqld.sock”连接到本地 MySQL 服务器

无法通过套接字“/opt/local/var/run/percona/mysqld.sock”连接到本地 MySQL 服务器

我已经在我的 Mac 机器上使用 Macports 安装了 Percona 服务器,但是我遇到了上面的套接字错误,如下所示:

Sauds-MacBook-Pro:percona jini$ sudo /opt/local/lib/percona/bin/mysql_secure_installation

    NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
          SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!


    In order to log into MySQL to secure it, we'll need the current
    password for the root user.  If you've just installed MySQL, and
    you haven't set the root password yet, the password will be blank,
    so you should just press enter here.

    Enter current password for root (enter for none): 
    ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/opt/local/var/run/percona/mysqld.sock' (2)

奇怪的是,我能够在命令行上使用 php 连接到 mysql。但当我尝试运行上述命令时,它失败了。

以下是我的my.cnf的内容:

[mysql]

# CLIENT #
port                           = 3306
socket                         = /opt/local/var/db/percona/mysql.sock

[mysqld]

# GENERAL #
user                           = mysql
default-storage-engine         = InnoDB
socket                         = /opt/local/var/db/percona/mysql.sock
pid-file                       = /opt/local/var/db/percona/mysql.pid

# MyISAM #
key-buffer-size                = 32M
myisam-recover                 = FORCE,BACKUP

# SAFETY #
max-allowed-packet             = 16M
max-connect-errors             = 1000000

# DATA STORAGE #
datadir                        = /opt/local/var/db/percona/

# CACHES AND LIMITS #
tmp-table-size                 = 32M
max-heap-table-size            = 32M
query-cache-type               = 0
query-cache-size               = 0
max-connections                = 10
thread-cache-size              = 16
open-files-limit               = 65535
table-definition-cache         = 1024
table-open-cache               = 2048

# INNODB #
innodb-flush-method            = O_DIRECT
innodb-log-files-in-group      = 2
innodb-log-file-size           = 5M
innodb-flush-log-at-trx-commit = 2
innodb-file-per-table          = 1
innodb-buffer-pool-size        = 12G

# LOGGING #
log-error                      = /opt/local/var/db/percona/mysql-error.log
log-queries-not-using-indexes  = 1
slow-query-log                 = 1
slow-query-log-file            = /opt/local/var/db/percona/mysql-slow.log

正如您所看到的,我没有在任何地方引用“opt/local/var/run/percona/mysqld.sock”,它仍在尝试在那里寻找该文件。

我只看到 /opt/local/var/db/percona 中列出了 mysql.sock

srwxrwxrwx   1 _mysql  _mysql         0 Jan 24 06:37 mysql.sock

另请参阅:

Sauds-MacBook-Pro:percona jini$ mysql_config --socket
/opt/local/var/run/percona/mysqld.sock

为什么它试图找到“/opt/local/var/run/percona/mysqld.sock”以及为什么我会收到这个错误?

更新:如果我创建一个符号链接:

sudo ln -s /opt/local/var/db/percona/mysql.sock /opt/local/var/run/percona/mysqld.sock

一切正常。但是我仍然不知道为什么我一开始没有 mysqld.sock 文件。

答案1

my.cnf可以位于几个不同的地方,其中一些优先于其他。看看https://stackoverflow.com/questions/2482234/how-to-know-mysql-my-cnf-location了解它们可能位于何处。如果您my.cnf在某处有另一个,它可能会从那里提取配置。

相关内容