连接数据报错ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

时间:2022-12-21 21:58:49

1、lamp环境使用数据库报错:

连接数据报错ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

2、编辑/etc/php.ini/文件中"mysql 下找到"mysql.default_socket",并设置其值指向正确的mysql服务socket文件即可,  在配置文件中添加“[client]”选项和“[mysql]”选项,并使用这两个选项下的“socket”参数值,与“[mysqld]”选项下的“socket”参数值,指向的socket文件路径完全一致。如下: 

连接数据报错ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

3、重启服务器就得以解决