Warning: mysql_connect(): Can't connect to local MySQL server

前端 未结 2 728
独厮守ぢ
独厮守ぢ 2020-12-21 06:09

Warning: mysql_connect(): Can\'t connect to local MySQL server through socket \'/var/lib/mysql/mysql.sock\' (11) in /home/aa/public_html/bb/db.php on line 2 Could not connec

相关标签:
2条回答
  • 2020-12-21 06:27

    That could mean that MYSQL is down or you use the wrong host name while connect. One more possible reason for that could be difference in socket configuration of php against mysql, you can check it in by looking at entry socket in mysql config. file and by looking at output of phpinfo(), you need just to compare it. Or it could that someone else on your machine also using that socket.

    PS. As well my wild guess, go through your code and check you always get your connection close right and all your queries as well.

    0 讨论(0)
  • 2020-12-21 06:31

    Make sure that your MySQL is running. OR Create a file called: phpinfo.php with the following inside it:

    <?php phpinfo(); ?>
    

    Load the file in your browser: http://localhost/phpinfo.php and scroll down for mysql. Look for the MYSQL_SOCKET and make sure it matches your entry in your my.cnf file.

    FYI, my my.cnf file is located in: /etc/my.cnf and it contains something like this:

    # The MySQL server
    [mysqld]
    port            = 3306
    socket          = /tmp/mysql.sock
    
    0 讨论(0)
提交回复
热议问题