Can't connect to local MySQL server through socket '/var/mysql/mysql.sock' (38)

后端 未结 30 2178
再見小時候
再見小時候 2020-11-22 04:23

I am having a big problem trying to connect to mysql. When I run:

/usr/local/mysql/bin/mysql start

I have the following error :

<         


        
相关标签:
30条回答
  • 2020-11-22 04:41

    If you are using AWS (Amazon Web Services) Micro version, then it is a memory issue. When I ran

    mysql
    

    from the terminal it would say

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

    So I tried the following and it would just fail.

    service mysqld restart
    

    After much searching, I found out that you have to create a swap file for MySQL to have enough memory. Instructions are listed: http://www.prowebdev.us/2012/05/amazon-ec2-linux-micro-swap-space.html.

    Then, I was able to restart mysqld.

    0 讨论(0)
  • 2020-11-22 04:42

    I got this error when I set cron job for my file. I changed the permissions of file to 777 but it still not worked for me. Finally I got the solution. May be it will be helpful for others.

    Try with this command:

    mysql -h 127.0.0.1 -P 3306 -u root -p

    Remember that -h means host, -P means port and -p means password.

    0 讨论(0)
  • 2020-11-22 04:43
    sudo service mysql start
    

    This should serve you just fine. There could be a possibility that you changed some commands that affected the mysql configurations.

    0 讨论(0)
  • 2020-11-22 04:44

    Make sure you are running mysqld : /etc/init.d/mysql start

    0 讨论(0)
  • 2020-11-22 04:45

    A quick workaround that worked for me: try using the local ip address (127.0.0.1) instead of 'localhost' in mysql_connect(). This "forces" php to connect through TCP/IP instead of a unix socket.

    0 讨论(0)
  • 2020-11-22 04:47

    you can always start mysql server by specifying the location of the mysql.sock file using the --socket option like

    mysql --socket=/var/mysql/mysql.sock 
    

    This will work even if the location of socket file in specified in a different location in the my.cnf file.

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