Reputation: 157
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 a p period of time or established connection failed because connected host has failed to respond.
I've seen this post and this but they were not answered.
Upvotes: 1
Views: 18974
Reputation: 422
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
Upvotes: 0