• 解决:error: 'Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)'


    在使用

    deamon@deamon-H55M-S2:/usr/bin$ mysqladmin -u root -p shutdown

    关闭MySQL之后试图通过:

    deamon@deamon-H55M-S2:/usr/bin$ mysqld_safe &

    来重启服务器,发现重启失败,显示权限不够:

    /usr/bin/mysqld_safe: 548: /usr/bin/mysqld_safe: cannot create /var/lib/mysql/mysqld_safe.pid: Permission denied

    于是加上sudo:

    deamon@deamon-H55M-S2:~$ sudo mysqld_safe&
    [4] 7998
    
    [4]+  Stopped                 sudo mysqld_safe
    deamon@deamon-H55M-S2:~$ mysql -u root -p
    Enter password: 
    ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

    然后就出现了如题所示的错误。

    解决方法是将用户切换成root,再重新启动。

    deamon@deamon-H55M-S2:~$ su -
    Password: 
    root@deamon-H55M-S2:~# mysqld_safe &
    [1] 8155
    root@deamon-H55M-S2:~# 2016-11-29T11:50:50.182755Z mysqld_safe Logging to syslog.
    2016-11-29T11:50:50.186438Z mysqld_safe Logging to '/var/log/mysql/error.log'.
    2016-11-29T11:50:50.209538Z mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
    
    root@deamon-H55M-S2:~# mysql -u root -p
    Enter password: 
    Welcome to the MySQL monitor.  Commands end with ; or g.
    Your MySQL connection id is 2
    Server version: 5.7.16-0ubuntu0.16.04.1 (Ubuntu)
    
    Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
    
    Oracle is a registered trademark of Oracle Corporation and/or its
    affiliates. Other names may be trademarks of their respective
    owners.
    
    Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.
    
    mysql> 

    此时将用户切换回原非root用户,mysql还可正常使用。至此该问题解决。

  • 相关阅读:
    HTTP响应状态码整理
    Python通用爬虫,聚焦爬虫概念理解
    HTTP无状态协议理解
    会话与事务知识点总结
    并发一致性知识点整理
    使用隔离级别read committed隐式解决并发冲突
    多并发笔记整理
    git基本使用
    Docker其他
    Docker Bind Mount 与 Volume
  • 原文地址:https://www.cnblogs.com/jiandahao/p/6115133.html
Copyright © 2020-2023  润新知