当前位置: 移动技术网 > IT编程>数据库>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)已解决

2020年07月14日  | 移动技术网IT编程  | 我要评论

说明

mysql版本: 8.0.20
系统: deepin

问题描述

安装、配置好mysql后是可以正常操作数据库的,但当我重启电脑后,再次登录时会报以下错误

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

猜测是因为没有开启mysql服务的原因,就像windows中配置好数据库后,要在设置中开始mysql服务,否则就无法登录。

所以尝试开启mysql服务

sudo mysql/support-files/mysql.server start

此处mysql是配置了环境变量的,若没有,则需在mysql安装目录下运行以下命令

sudo ./support-files/mysql.server start

此时,我们再登录mysql,就可以了。

但每次登录都要执行该命令,比较麻烦。所以我们配置mysql.server的开机自启动。

  1. 复制该文件到etc目录下
    sudo cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
    
  2. 创建rc.local文件
    sudo vim /etc/rc.local
    
  3. 在文件中添加以下内容
    #!/bin/bash 
    # rc.local config file created by use
     
    service mysqld start
     
    exit 0
    
    
  4. 添加可执行权限
    sudo chmod +x /etc/rc.local
    

本文地址:https://blog.csdn.net/qq_43366662/article/details/107316535

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网