2

I am on a problem since yesterday that I can not solve.

The error appears when I want to connect to the database of a host, the error is No such file or directory, I looked for the path of the socket file and the path is / var / run / mysqld /mysqld.sock so I changed the file path. Locally its function the solution that I have on the net but in production no

here is the conf of the laravel .env file

DB_Connection = mysql

DB_HOST = hXXmysqlXXX

DB_PORT = 3306

DB_DATABASE = XXX_test
DB_USERNAME = XXX_bdd

DB_PASSWORD = XXXX

'# DB_SOCKET = / tmp / mysql.sock (it's a comment)

DB_SOCKET = /var/run/mysqld/mysqld.sock

Unfortunately, this did not solve the error.

Could you help me solve the problem?

Thank you

(I have already researched the problem and did not find a solution.Excuse me for my english, it's not my mother tongue)

diego
  • 408
  • 8
  • 21
  • 3
    Possible duplicate of [PDOException SQLSTATE\[HY000\] \[2002\] No such file or directory](https://stackoverflow.com/questions/20723803/pdoexception-sqlstatehy000-2002-no-such-file-or-directory) – Jerodev Jan 30 '18 at 14:32
  • the error is not similar because the error is on the server and not in localhost. it works localhost @Jerodev – diego Jan 30 '18 at 14:37
  • It is the same problem. Your database on the server is probably running on a different location. – Jerodev Jan 30 '18 at 14:37
  • it's not similar because locally its function but in production no @Jerodev – diego Jan 30 '18 at 14:52

1 Answers1

3

Are you looking for connect to a local database or a remote database (a database located on other computer/server) ?

On Unix, MySQL programs treat the host name localhost specially, in a way that is likely different from what you expect compared to other network-based programs.

For connections to localhost, MySQL programs attempt to connect to the local server by using a Unix socket file. This occurs even if a --port or -P option is given to specify a port number.

To ensure that the client makes a TCP/IP connection to the local server, use --host or -h to specify a host name value of 127.0.0.1, or the IP address or name of the local server. You can also specify the connection protocol explicitly, even for localhost, by using the --protocol=TCP option.

protocol could be {TCP|SOCKET|PIPE|MEMORY}

in short: you don't have to specify a sock file for remote connections.

danilonet
  • 1,757
  • 16
  • 33
  • In laravel, this file (.env) is necessary to establish a connection to the database. To establish the connection of the database locally, the variables of the file changes (DB_DATABASE - DB_SOCKET ...) .In local I do not have the error it is only in production when I put it on the host . – diego Jan 30 '18 at 14:49
  • @diego i got something similar error here can you look at that https://stackoverflow.com/questions/60796332/this-php-code-works-in-localhost-but-not-on-server thank you – Kiran Patel Mar 22 '20 at 06:01