mysql启动报错:Can‘t connect to local MySQL server through socket

文章目录

  • 一、报错内容
  • 二、解决方法

一、报错内容

在linux上启动mysql时报错

[root@localhost bin]# ./mysql -u root -p
Enter password: 
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

执行以上命令后报错,并且也没有找到/tmp/mysql.sock文件。

二、解决方法

首先,虽然我们配置了my.cnf文件,但调用该文件的路径不一定是对的。

打开mysql安装路径下的/usr/local/mysql-8.0/support-files/mysql.server
mysql启动报错:Can‘t connect to local MySQL server through socket_第1张图片
确认这个路径与实际的配置文件路径相同,否则cnf文件无法起作用。因为是通过mysql.server文件进行启动的。

我的报错就是因为这里路径不一致导致的,所以将my.cnf文件放到/etc/my.cnf文件中就好了

你可能感兴趣的:(数据库,mysql报错)