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

前端 未结 30 1029
离开以前
离开以前 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 02:56

    I once had this problem and solved it by installing mysql-server, so make sure that you have installed the mysql-server, not the mysql-client or something else.

    That error means the file /var/run/mysqld/mysqld.sock doesn't exists, if you didn't install mysql-server, then the file would not exist. So in that case, install it with

    sudo apt-get install mysql-server
    

    But if the mysql-server is already installed and is running, then you need to check the config files.

    The config files are:

    /etc/my.cnf
    /etc/mysql/my.cnf
    /var/lib/mysql/my.cnf
    

    In /etc/my.cnf, the socket file config may be /tmp/mysql.sock and in /etc/mysql/my.cnf the socket file config may be /var/run/mysqld/mysqld.sock. So, remove or rename /etc/mysql/my.cnf, let mysql use /etc/my.cnf, then the problem may solved.

    0 讨论(0)
  • 2020-11-22 02:56

    I FOUND THE SOLUTION

    Before firing the command : mysql_secure_installation

    • Step 1: sudo systemctl stop mariadb
    • Step 2: sudo systemctl start mariadb
    • Step 3: mysql_secure_installation

    Then it will ask root password and you can simply press Enter and set your new root password.

    0 讨论(0)
  • 2020-11-22 02:58

    Try this:

    mysql -h 127.0.0.1 -P 3306 -u root -p <database>
    

    Also (to see if it's running):

    telnet 127.0.0.1 3306 
    

    Probably it is just a misconfiguration in the my.cnf file, in /etc/somewhere (depending on the Linux distribution).

    0 讨论(0)
  • 2020-11-22 02:58

    Here's what worked for me:

    ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock
    service mysql restart
    

    This creates a link.

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

    Check if you have the correct rights:

    sudo chmod 755 /var/lib/mysql/mysql
    

    I had the same problems and this worked for me. After doing this I was able to start MySQL.

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

    Check the "bind-adress" parameter in my.cnf.

    Else try with the command:

    mysql -h 127.0.0.1 -P 3306 -u root -p
    
    • -h for host 127.0.0.1, that is, localhost

    • -P (notice -P as uppercase) for port 3306, that is, the default port for MySQL

    0 讨论(0)
提交回复
热议问题