Share via

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 App Service
Azure App Service

Azure App Service is a service used to create and deploy scalable, mission-critical web apps.


Answer accepted by question author

  1. SSingh-MSFT 16,461 Reputation points Moderator
    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' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.