我有一个大问题试图连接到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]

当前回答

我在Freebsd上也有同样的问题,我通过删除my.cnf文件解决了这个问题。 Mysql的版本是5.6。

从5.5升级后,旧的my.cnf似乎仍然存在,一些不兼容的参数迫使一个错误。 旧的my.cnf有很多参数,但新的只有一个

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

但是如果你这样做了,请记住这可能是一个安全风险,因为没有任何进一步的输入可能会将你的数据库向世界其他地方开放;-) 如果不加,至少要加这条线

bind-address = 127.0.1.1

其他回答

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

service mariadb start

另外:

chkconfig mariadb on

我今天遇到了这个问题。这些答案都不能解决问题。我需要做以下命令(在这里找到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的命令时。如果权限检查失败,则报告磁盘已满(即使您的分区还没有接近满)。

你确定你安装了MySQL和MySQL服务器吗?

例如,要安装MySQL服务器,我将使用yum或apt安装MySQL命令行工具和服务器:

yum -y install mysql mysql-server (or apt-get install mysql mysql-server)

启动MySQL服务:

/sbin/chkconfig mysqld on

启动MySQL服务器:

/sbin/service mysqld start

然后设置MySQL root密码:

mysqladmin -u root password 'new-password' (with the quotes)

我得到了以下错误:

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (111)

尝试了几种方法,最终通过以下方法解决:

sudo gksu gedit /etc/mysql/my.cnf

修改:

#bind-address       = 127.0.0.1

to:

bind-address        = localhost

并重新启动:

sudo /etc/init.d/mysql restart

它工作。

如果有人在寻找初始化错误

无法连接数据库/var/run/mysql/mysql.sock

当运行民事管理和drupal时,只需在

settings。php和civil。settings。php

只有在你试图建立数据库连接的地方

Localhost到127.0.0.1 #本地安装