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

当前回答

搞了两天之后,我想说说我的看法,

你在用hhvm吗?

如果是,在/etc/hhvm/server.ini中追加下一行

hhvm.mysql.socket = /var/run/mysqld/mysqld.sock

其他回答

你确定你安装了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)

对我来说,这只是一个MySQL需要很长时间加载的情况。我的一个数据库中有超过10万个表,它最终启动了,但显然在这种情况下需要很长时间。

我已经删除了mysql。袜子锉成功了。给它加上版权根本没用。既不是重启,也不是别的……

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

当我试图启动服务器时,我也遇到了这个问题,这里的许多答案只是说启动服务器不起作用。你可以做的第一件事是执行以下命令,看看是否有任何配置错误:

/usr/sbin/mysqld --verbose --help 1>/dev/null

我确实出现了一个错误:

160816 19:24:33 [Note] /usr/sbin/mysqld (mysqld 5.5.50-0ubuntu0.14.04.1-log) starting as process 9461 ...
160816 19:24:33 [Warning] Using unique option prefix myisam-recover instead of myisam-recover-options is deprecated and will be removed in a future release. Please use the full name instead.
160816 19:24:33 [Note] Plugin 'FEDERATED' is disabled.
160816 19:24:33 [ERROR] /usr/sbin/mysqld: unknown variable 'innodb-online-alter-log-max-size=4294967296'
160816 19:24:33 [ERROR] Aborting

简单的grep -HR "innodb-online-alter-log-max-size" /etc/mysql/显示了包含违规行文件的文件,所以我从文件中删除了这一行。

然后,检查我的/var/log/mysql/error.log文件:

InnoDB: Error: log file ./ib_logfile0 is of different size 0 5242880 bytes
InnoDB: than specified in the .cnf file 0 671088640 bytes!
160816 22:46:46 [ERROR] Plugin 'InnoDB' init function returned error.
160816 22:46:46 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
160816 22:46:46 [ERROR] Unknown/unsupported storage engine: InnoDB
160816 22:46:46 [ERROR] Aborting

基于这个问题,接受的解决方案不会工作,因为我甚至无法启动服务器,所以我按照一些评论说的,删除了我的/var/lib/mysql/ib_logfile0和/var/lib/mysql/ib_logfile1文件。

这允许服务器启动,我能够连接和执行查询,但是检查我的错误日志文件,它很快就被这样的数万行填满了:

160816 22:52:15  InnoDB: Error: page 1415 log sequence number 82039318708
InnoDB: is in the future! Current system log sequence number 81640793100.
InnoDB: Your database may be corrupt or you may have copied the InnoDB
InnoDB: tablespace but not the InnoDB log files. See
InnoDB: http://dev.mysql.com/doc/refman/5.5/en/forcing-innodb-recovery.html
InnoDB: for more information.

根据这里的建议,为了解决这个问题,我做了一个mysqldump并恢复了所有数据库(参见其他几个解决方案的链接)。

$ mysqldump -u root -p --allow-keywords --add-drop-database --comments --hex-blob --opt --quote-names --databases db_1 db_2 db_3 db_etc > backup-all-databases.sql
$ mysql -u root -p < backup-all-databases.sql

现在一切似乎都在按预期进行。