我有一个大问题试图连接到mysql。当我跑步时:

/usr/local/mysql/bin/mysql start

我有以下错误:

Can't connect to local MySQL server through socket '/var/mysql/mysql.sock' (38)

我有mysql。Sock在/var/mysql目录下。

在/etc/my.cnf中,我有:

[client]
port=3306
socket=/var/mysql/mysql.sock

[mysqld]
port=3306
socket=/var/mysql/mysql.sock
key_buffer_size=16M
max_allowed_packet=8M

在/etc/php.ini中有:

; Default socket name for local MySQL connects.  If empty, uses the built-in
; MySQL defaults.
mysql.default_socket = /var/mysql/mysql.sock

我已经使用sudo /opt/local/apache2/bin/apachectl restart重启apache

但还是有误差。

否则,我不知道这是否相关,但当我执行mysql_config——sockets时,我得到

--socket         [/tmp/mysql.sock]

当前回答

我今天遇到了这个问题。这些答案都不能解决问题。我需要做以下命令(在这里找到https://stackoverflow.com/a/20141146/633107)为我的mysql服务启动:

sudo /etc/init.d/mysql stop
cd /var/lib/mysql/
ls ib_logfile*
mv ib_logfile0 ib_logfile0.bak
mv ib_logfile1 ib_logfile1.bak
... etc ...
/etc/init.d/mysql restart

这部分是由/var/log/mysql/error.log中的以下错误指示的:

140319 11:58:21 InnoDB: Completed initialization of buffer pool
InnoDB: Error: log file ./ib_logfile0 is of different size 0 50331648 bytes
InnoDB: than specified in the .cnf file 0 5242880 bytes!
140319 11:58:21 [ERROR] Plugin 'InnoDB' init function returned error.
140319 11:58:21 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
140319 11:58:21 [ERROR] Unknown/unsupported storage engine: InnoDB
140319 11:58:21 [ERROR] Aborting

我还看到磁盘已满错误,但只有在运行没有sudo的命令时。如果权限检查失败,则报告磁盘已满(即使您的分区还没有接近满)。

其他回答

尝试使用-h(主机)和-P(端口):

mysql -h 127.0.0.1 -P 3306 -u root -P

从这里的许多答案可以看出,在启动MySQL服务时,有许多问题会导致这个错误消息。问题是,MySQL通常会告诉你哪里出了问题,如果你只查看适当的日志文件。

例如,在Ubuntu上,你应该检查/var/log/syslog。由于许多其他内容也可能记录到这个文件中,您可能希望使用grep查看mysql消息,而tail只查看最近的消息。所有这些加在一起,可能是这样的:

Grep mysql /var/log/syslog | tail -50

不要因为别人说“这适用于我的系统”就盲目地更改您的配置。找出你的系统到底出了什么问题,你就能更快地得到更好的结果。

我刚刚遇到了这个问题。经过一天的检查,我终于得到了答案,mysql。sock文件在MariaDB启动时创建,在MariaDB关闭时删除。如果MariaDB不运行,它就不存在。 也许你没有安装MariaDB。 你可以按照下面的说明操作: https://www.linode.com/docs/databases/mariadb/how-to-install-mariadb-on-centos-7 最好的

sudo service mysql start

这应该对你很有用。有可能您更改了一些影响mysql配置的命令。

在我的情况下,解决方案是我安装了mariadb,它的别名是mysql。所以所有与mysql相关的服务命令都不被识别…我只需要:

service mariadb start

另外:

chkconfig mariadb on