trouble connecting to MySql DB (PHP)

后端 未结 4 1598
故里飘歌
故里飘歌 2021-01-27 12:16

I have the following PHP code to connect to my db:



        
相关标签:
4条回答
  • 2021-01-27 12:30

    Maybe your MySQL is not using TCP for localhost. Please try

    $host='/tmp/mysql.sock';
    

    or whatever socket it might be using.

    0 讨论(0)
  • 2021-01-27 12:32

    I also have noticed this issue linux version of xampp with MySSQL 5.6.12-log running over network. Also, a question asked in MySQL forum (http://forums.mysql.com/read.php?52,294772,294772) resembles this, but not satisfactorily answered.

    What I have noticed is, it is probably due to Networking being unstable, or too many mysql connections from other developers in the network connecting to the database server at the same time - and keeping the port number busy for a fraction of time. It is not often related to the configured connection time, nor maximum execution time, nor wrong username/password etc.

    Amazingly, the same script, same password, and same network allows the same server run properly on the second attempt - without having to do anything as a fix.

    Hence, it should be your momentarily unstable network fluctuation (or busy mysql connections), that goes on and off, and your script attempted to connect to the server when network was down for a very short time.

    That is a guessed answer from personal experience related to this error, may not be exact.

    But if the error message is persistent, you should really need to do something.

    0 讨论(0)
  • 2021-01-27 12:38

    Check the following:

    1. Is MySQL running?
    2. Is there any firewall that could be blocking your computer from accepting connections to MySQL on port 3306?
    3. Is MySQL listening on port 3306, or did it get changed to something nonstandard?
    4. An odd one, but try changing from localhost to 127.0.0.1

    Basically, the errors you're getting mean that it cannot connect to the server. It sends request to localhost:3306, and only waits so long for a reply. it's not getting it, which means the request is either blocked (firewall) or ignored (MySQL is not running and/or is listening on a different port)

    If phpMyAdmin came with the MySQL install, then it could be that it was configured to use the appropriately different port

    0 讨论(0)
  • 2021-01-27 12:42

    ha i also had that issue now i fix it by changing port number e.g "find.db.13344.hostedfind.com:3306". before it my connection was trying to access the "find.db.13344.hostedfind.com:3307" so it gave me this error Warning: mysql_connect() [function.mysql-connect]: [2002] A connection attempt failed because the connected party did not (trying to connect via tcp://localhost:3306) .

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