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

Aleksandar Simovic 51 Reputation points
2022-11-07T09:01:28.157+00:00

Hello all,

I am trying to access mysql through web ssh in Linux php app service, but I am getting this error:

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

Is there anybody who can help me about this one?

Best regards,
Aleksandar

Azure Database for MySQL
Azure Database for MySQL
An Azure managed MySQL database service for app development and deployment.
850 questions
Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
7,924 questions
{count} votes

Accepted answer
  1. ShaktiSingh-MSFT 15,501 Reputation points
    2022-11-07T10:42:01.01+00:00

    Hi @Aleksandar Simovic ,

    Thanks for posting this question in Microsoft Q&A platform.

    As I understand the question, you are trying to access mysql through web ssh in Linux php app service, but getting this error:

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

    Could you please try modifying bind-address to localhost and restart, if this helps.

    sudo gksu gedit /etc/mysql/my.cnf  
    

    Modify:

    bind-address = 127.0.0.1
    to:

    bind-address = localhost

    and restart:

    sudo /etc/init.d/mysql restart

    Another option is if your file my.cnf (usually in the /etc/mysql/ folder) is correctly configured with:

    socket=/var/lib/mysql/mysql.sock  
    

    You can check if mysql is running with the following command:

    mysqladmin -u root -p status  
    

    Try changing your permission to mysql folder. If you are working locally, you can try:

    sudo chmod -R 755 /var/lib/mysql/  
    

    Hope this will help. Please let us know if any further queries.

    ------------------------------

    • Please don't forget to click on 130616-image.png or upvote 130671-image.png button whenever the information provided helps you.
      Original posters help the community find answers faster by identifying the correct answer. Here is how
    • Want a reminder to come back and check responses? Here is how to subscribe to a notification
    2 people found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.