Mysql错误ERROR 2002(HY000)在完全重新安装后仍然存在

时间:2016-12-17 00:02:46

标签: mysql ruby-on-rails ubuntu

所以我一直在使用MySQL的rails服务器,突然无法访问我的数据库。当我尝试使用mysql -u root -p登录时,我得到ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)。我已经阅读了我能找到的大多数论坛,并查看了所有尝试重置mysqld.sock的日志。我尝试重新安装和重新包装失败。奇怪的是重新安装后var / run / mysqld /甚至不存在。

所以我决定只备份我的数据库并检查所有内容。我用apt-get remove --purge清除了apache和mysql并重新安装。一切顺利,apache启动正常,然后尝试用systemctl start mysql重启mysql,提示检查日志说:

  ● mysql.service - MySQL Community Server
   Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
   Active: inactive (dead) (Result: exit-code) since Fri 2016-12-16 23:56:19 UTC; 17s ago
  Process: 15690 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=1/FAILURE)

Dec 16 23:56:19 ip-172-31-0-55 systemd[1]: mysql.service: Control process exited, code=exited status=1
Dec 16 23:56:19 ip-172-31-0-55 systemd[1]: Failed to start MySQL Community Server.
Dec 16 23:56:19 ip-172-31-0-55 systemd[1]: mysql.service: Unit entered failed state.
Dec 16 23:56:19 ip-172-31-0-55 systemd[1]: mysql.service: Failed with result 'exit-code'.
Dec 16 23:56:19 ip-172-31-0-55 systemd[1]: mysql.service: Service hold-off time over, scheduling restart.

Dec 16 23:56:19 ip-172-31-0-55 systemd[1]: Stopped MySQL Community Server.
Dec 16 23:56:19 ip-172-31-0-55 systemd[1]: mysql.service: Start request repeated too quickly.
Dec 16 23:56:19 ip-172-31-0-55 systemd[1]: Failed to start MySQL Community Server.

更新 - 我创建了文件夹mysqld,它似乎允许sudo mysqld --initialize运行。不幸的是,这产生了错误 2016-12-17T00:16:36.298825Z 0 [ERROR] Can't change data directory owner to mysql 2016-12-17T00:16:36.299212Z 0 [ERROR] Aborting

所以还没有派对。任何想法都会非常感激。

1 个答案:

答案 0 :(得分:1)

修改/etc/mysql/conf.d/mysql.cnf

sudo nano /etc/mysql/conf.d/mysql.cnf

添加此行: socket=/var/run/mysqld/mysqld.sock

然后重启mysql服务:

sudo service mysql restart