简体   繁体   English

MySQL 无法连接 Ubuntu

[英]MySQL can't connect Ubuntu

Can't connect to MySQL service.无法连接到 MySQL 服务。 Below is the status output error I get when trying to start下面是我在尝试启动时得到的状态输出错误

Job for mysql.service failed because the control process exited with error code. mysql.service 的作业失败,因为控制进程退出并显示错误代码。 See "systemctl status mysql.service" and "journalctl -xe" for details.有关详细信息,请参阅“systemctl status mysql.service”和“journalctl -xe”。

ruan@master.danzlive.com:~$ systemctl status mysql.service
● mysql.service - MySQL Community Server
   Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
   Active: activating (start-post) since Tue 2018-10-30 11:59:35 SAST; 1s ago
  Process: 1988 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
 Main PID: 1998 (mysqld); Control PID: 1999 (mysql-systemd-s)
    Tasks: 16 (limit: 19660)
   Memory: 130.2M
      CPU: 577ms
   CGroup: /system.slice/mysql.service
           ├─1998 /usr/sbin/mysqld
           └─control
             ├─1999 /bin/bash /usr/share/mysql/mysql-systemd-start post
             └─2031 sleep 1

Oct 30 11:59:35 ip-197-101-38-62 systemd[1]: Starting MySQL Community Server...
ruan@master.danzlive.com:~$ mysql
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

I faced similar Issue in Ubuntu 18.04.我在 Ubuntu 18.04 中遇到了类似的问题。 I found the reason that - On last day I cleared Ubuntu using Stacer Application.我找到了原因 - 最后一天我使用 Stacer 应用程序清除了 Ubuntu。 This application removed mysql log folder at location此应用程序删除了位置处的 mysql 日志文件夹

/var/log/

So next day while starting MySQL, got this error.所以第二天在启动 MySQL 时,出现了这个错误。 I created that folder again and given permissions.我再次创建了该文件夹并授予了权限。

mkdir /var/log/mysql
sudo chown mysql:mysql -R /var/log/mysql

尝试通过命令行直接使用-u参数添加数据库用户名。

mysql -u root <database>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM