开发者

pdo_mysql unable to create mysqld.sock file

开发者 https://www.devze.com 2023-03-21 06:08 出处:网络
I\'m adding PHP (php-fpm) to an existing Nginx Ubuntu 10.04 server and can\'t get pdo_mysql to work. I\'m trying to connect to a MySQL server someplace else, but all the Googling answers I found are i

I'm adding PHP (php-fpm) to an existing Nginx Ubuntu 10.04 server and can't get pdo_mysql to work. I'm trying to connect to a MySQL server someplace else, but all the Googling answers I found are in regards to MySQL not working on the local server, so I'm not sure how to proceed.

I don't have mysqld installed, so I'm not sure if I need it, or if there's a way around this? Also I'm wondering if it can't create mysqld.sock because there is mysql user on the server?

Error:

SQLSTATE[HY000] [2002] Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) Fatal error: Call to a member function query() on a non-object

My PHP connection code:

$this->PDO = new PDO('mysql:host=' . $this->config->getValue('db_host') .
                             ';dbname=' . $this->config开发者_如何学Go->getValue('db_name'),
                             $this->config->getValue('db_user'),
                             $this->config->getValue('db_pass'));

My Query line it fails on:

$PDOStatement = $this->PDO->query($query);

Appreciate any help, thanks.


Couple of things you should check

  • D you have mysql-client installed? if you are connecting to remote machine. you don't need mysql running on your box but I think you will still need the client.
  • Make sure the host value is correct. Double & triple check

  • Lastly, Try connecting manually using command line, by the following command.

$ mysql -u <INSERT_USER_HERE> -p -h <INSERT_IP_OF_REMOTE_MACHINE_HERE> <INSERT_DB_NAME_HERE>

If it does not work. come back with exact error message.


Your server is attempting to connect to a local MySQL instance. If your database is on a different remote server, make sure that the the db_host value of your configuration file points to the correct hostname of the MySQL server.

You do not need mysqld installed, but you do need MySQL client libraries.


Are you sure that $this->config->getValue('db_host') is returning the correct value? The behavior you're describing sounds a lot like it's returning an empty or null value.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号