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

前端 未结 30 1146
离开以前
离开以前 2020-11-22 02:25

I installed LAMP on Ubuntu 12.04 LTS (Precise Pangolin) and then set root password on phpMyAdmin. I forgot the password and now I am unable to login. When I try to chan

相关标签:
30条回答
  • 2020-11-22 03:06

    By experience I say that you need to check if the server is running first and then try configuring MySQL. The last solution is to re-install MySQL.

    0 讨论(0)
  • 2020-11-22 03:07

    In my case, the default port 3306 was being used by some other process and thus it was not starting. After I stopped the other service and did sudo service mysql start, it worked fine. BTW, you can use something like sudo lsof -Pn -iTCP:3306 to see who may be using the port.

    0 讨论(0)
  • 2020-11-22 03:08

    Instead of using localhost:

    mysql -u myuser -pmypassword -h localhost mydatabase
    

    Use 127.0.0.1

    mysql -u myuser -pmypassword -h 127.0.0.1 mydatabase
    

    (also note, no space between -p and mypassword)

    Enjoy :)

    0 讨论(0)
  • 2020-11-22 03:08

    On Debian server Jessie, my working solution was to simply do

    service mysql restart
    service mysql reload
    

    as root user

    0 讨论(0)
  • 2020-11-22 03:12

    If your installation was recent, you should to confirm if your installation is the installation SERVER... as mysql-server-5.5.. Maybe you installed only "mysql" .. this is only client instead of the server.

    0 讨论(0)
  • 2020-11-22 03:14

    I had a similar problem. mysql wouldn't start:

    sudo service mysql start
    start: Job failed to start
    

    If I disabled apparmor:

    sudo aa-complain /etc/apparmor.d/*
    

    the problem went away. The issue was that mysqld was trying to access /run/mysqld/mysqld.sock but the apparmor profile only gave permission to /var/run/mysqld/mysqld.sock (/var/run is symlinked to /run, so these are actually the same). Not sure why mysqld isn't using the var path since that's what's set in all the configuration files, but you can fix the problem by adding the following to /etc/apparmor.d/usr.sbin.mysqld

    /run/mysqld/mysqld.pid rw,
    /run/mysqld/mysqld.sock rw,
    
    0 讨论(0)
提交回复
热议问题