Can t connect to local MySQL server through socket /tmp/mysql.sock

不能通过'/tmp/mysql.sock'连到服务器,而php标准配置正是用过'/tmp/mysql.sock',但是一些mysql安装方法将

mysql.sock放在/var/lib/mysql.sock或者其他的什么地方,你可以通过修改/etc/my.conf文件来修正它

首先是mysqld启动不了,

我通过vim /etc/my.cnf,修改了[mysqld]选项下面的socket的值
socket=/var/lib/mysql/mysql.sock
ok,mysqld可以启动了

接下来,是mysql启动不了,同样,vim /etc/my.cnf,添加了如下脚本:

[mysql]

socket=/var/lib/mysql/mysql.sock

然后,mysqladmin启动不了,还是一样,在[mysqladmin]下面socket值设置为同样的路径
ok,可以启动了

最后,用php连接的时候,又出现这个问题了

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

我首先想到的是,在/etc/php.ini修改mysql.default_socket的值,在这个文件中,关于mysql.default_socket的

值的说明是这样的,

; Default socket name for local MySQL connects.  If empty, uses the built-in MySQL defaults.
这个值一开始是空的,也就是说,如果我们不主动去修改的话,php将会使用内建在mysql中的默认值
于是,我修改了这个值,设置为:

mysql.default_socket=/var/lib/mysql/mysql.sock

然后我重新启动apache,结果无效;reboot系统,结果无效

我火大了,php就非得去连接/tmp/mysql.sock,可是我的系统里面就是没有这个路径下的这个文件,那我就给你链

接一个,于是我做了下面的操作,

ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock

怎样保护“/tmp/mysql.sock   ”不被删除

如果你有这个问题,事实上任何人可以删除MySQL通讯套接字“/tmp/mysql.sock”,在Unix的大多数版本上,你能

通过为其设置sticky(t)位来保护你的“/tmp”文件系统。作为root登录并且做下列事情:

shell>   chmod   +t   /tmp

这将保护你的“/tmp”文件系统使得文件仅能由他们的所有者或超级用户(root)删除。

你能执行ls   -ld   /tmp检查sticky位是否被设置,如果最后一位许可位是t,该位被设置了。

时间: 2024-10-23 07:01:59

Can t connect to local MySQL server through socket /tmp/mysql.sock的相关文章

XtraBackup出现 Can't connect to local MySQL server through socket '/tmp/mysql.sock'

Xtrabackup做备份时遇到下面错误信息MySQL server: Can't connect to local MySQL server through socket '/tmp/mysql.so'(2)   [root@MySQL-DB ~]# innobackupex --defaults-file=/usr/my.cnf --user=root --password=password  /mnt/resource/mysql_backup 160322 22:28:43 innoba

解决Can't connect to local MySQL server through socket '/tmp/mysql.sock'错误

风信网(ithov.com)原创文章:刚安装完mysql,进行运行测试,报Can't connect to local MySQL server through socket '/tmp/mysql.sock'错误, [root@localhost mysql]# /usr/local/mysql/bin/mysqld_safe 131206 22:42:51 mysqld_safe Logging to '/var/log/mysqld.log'. 131206 22:42:51 mysqld

Ruby on Rails 3 Can't connect to local MySQL server through socket '/tmp/mysql.sock' on linux

Ruby on Rails 3 Can't connect to local MySQL server through socket '/tmp/mysql.sock' on linux 解决办法: up vote1down voteaccepted First, to find your socket file: mysqladmin variables | grep socket For me, this gives: | socket | /tmp/mysql.sock | 2  Then

ERROR 2002 (HY000): Cant connect to local MySQL server through socket的解决方法

连接MySQL提示ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)的解决方法 ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) 原文:http://www.aiezu.com/db/mysql_cant_connect_thro

启动MYSQL提示:Can’t connect to MySQL through socket ‘/tmp/mysql.sock’

启动MYSQL是出现以下错误: [root@www ~]# /usr/local/webserver/mysql/bin/mysqladmin -u root -p 12345678 Enter password: /usr/local/webserver/mysql/bin/mysqladmin: connect to server at 'localhost' failed error: 'Can't connect to local MySQL server through socket

MYSQL错误解决:ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) 据说这个问题的原因很多,当然,我自己这个问题我是清楚的,就是mysql.sock的位置所致,一个是PHP要求的,一个是MYSQLD定义的,一个是MY.CONF指定的...SO.... 暂时不能统一的话,用软链接LN -S命令解决吧..   方案5      摘要:解决不能通过mysql .so

MYSQL错误解决:ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) 据说这个问题的原因很多,当然,我自己这个问题我是清楚的,就是mysql.sock的位置所致,一个是PHP要求的,一个是MYSQLD定义的,一个是MY.CONF指定的...SO.... 暂时不能统一的话,用软链接LN -S命令解决吧..   方案5      摘要:解决不能通过mysql .so

Can’t connect to local MySQL server through socket

mysql,Mysqldump,Mysqladmin,php连接mysql服务常会提示下面错误: 1 ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) 这是由于修改mysql服务的了socket文件mysql.sock位置,而导致无法通过mysql socket文件连接到mysql服务引起的,具体解决办法如下:1.查看mysql服务的sock

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

从供应商手中接手一个云平台(Windwos Azure)上的MySQL数据库,登录数据库时遇到错误: $mysql -uroot -p Enter password: ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) 检查配置文件/etc/my.cnf发现供应商修改了mysql数据库的数据存储目录,另外mysql.sock文件位置也变更为了/