I'm trying to connect to my remote mysql database ( infinityfree.net ) in my Laravel ( Version 5.6 ) application. This is my configuration in database.php file:
'mysql' => [
'driver' => 'mysql',
'host' => 'sql201.epizy.com',
'database' => 'epiz_22148680_LaravelHospital',
'username' => 'epiz_22148680',
'password' => 'Vxp7****R1k6',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
],
I also changed the .env file:
DB_CONNECTION=mysql
DB_HOST=sql201.epizy.com
DB_PORT=3306
DB_DATABASE=epiz_22148680_LaravelHospital
DB_USERNAME=epiz_22148680
DB_PASSWORD=Vxp7****R1k6
However, when I try to connect to my database I get this error:
PDOException::("SQLSTATE[HY000] [2002] A connection attempt failed because the connected party did not properly respond after ap period of time or established connection failed because connected host has failed to respond.
By default, remote access to the MySQL database server is disabled for security reasons. MySQL instance is only configured to listen for local connections. This is MySQL's default setting, but it won't work for a remote database setup since MySQL must be able to listen for an external IP address where the server can be reached.
To enable this, open up your mysqld.cnf file:
look for the following line,
bind-address = 127.0.0.1
for the purpose of troubleshooting change it to 0.0.0.0.
restart MySQL and check the connection again.
if its working change 0.0.0.0 to yourWEBSERVERIPaddress
if you have any problems here is the complete tutorial.
https://www.cyberciti.biz/tips/how-do-i-enable-remote-access-to-mysql-database-server.html
Look the libraries of php-mysql are instaled?
look php -m, for view the modules.
Just setting .env is enough to connecto for db
This basically means that no response (either positive or negative) was received from the remote host when the TCP connection attempt took place. One reason this may happen is because a firewall is blocking the response from the server. Another reason is that the host name is incorrect. This could also mean there is a (temporary) problem with the server (or some router along the way). You can try a traceroute to determine whether or not this is true.
Solution
Make sure that the host name is correct Unblock SmartFTP in the software firewall and antivirus product Check if there is a temporary problem with the server
You should figure out if the host got real ip.If the ip is not static then the connection cannot be established.
and before all this, try
php artisan config:cache
if you are using docker or any other similar service,reboot the container and try again and also make sure that the Host is using the same MySQL (3306) por t in this case.It can pretty well be a different port.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.