0
votes

I'm an irregular Laravel user, and am trying to connect to a remote SQL database.

I've gotten the artisan commands working to create migrations and from the command line I can successfully connect to the database. But, when I try to load the application, the connection fails.

Could not connect to the database. Please check your configuration. error:PDOException: SQLSTATE[HY000] [1045] Access denied for user 'myuser'@'222.222.222.222' (using password: YES) in ... {file location} 

What are artisan and the actual app framework doing differently that this connection would respond differently between the 2?

Here is the mysql connection in the database.php file:

'mysql' => [
        'driver' => 'mysql',
        'host' => env('DB_HOST', '123.123.123.123'),
        'port' => env('DB_PORT', '3306'),
        'database' => env('DB_DATABASE', 'mydb'),
        'username' => env('DB_USERNAME', 'myuser'),
        'password' => env('DB_PASSWORD', 'mypass'),
        'unix_socket' => env('DB_SOCKET', ''),
        'charset' => 'utf8mb4',
        'collation' => 'utf8mb4_unicode_ci',
        'prefix' => '','strict' => true,
        'engine' => null,
        'sslmode' => 'require',
        'options'   => array(
            PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT => false,
            PDO::MYSQL_ATTR_SSL_KEY => 'certs/client-key.pem',
            PDO::MYSQL_ATTR_SSL_CERT => 'certs/client-cert.pem',
            PDO::MYSQL_ATTR_SSL_CA => 'certs/server-ca.pem',
        ),

And this is the local environment file:

DB_CONNECTION=mysql
DB_HOST=123.123.123.123
DB_PORT=3306
DB_DATABASE=mydb
DB_USERNAME=myuser
DB_PASSWORD=mypass

I am running the application locally, but the MySQl server is remote.

1
Is your remote database authentication is tunnel based ? if yes then you have to create tunnel and you'll need that open in order to use DB connection in the application.Gammer
It turns out that the root cause was that PDO doesn't like the cert generated by Google Cloud SQL.bluemoon6790
glade its solved now.Gammer
You can answer your own question now.Gammer

1 Answers

0
votes

It turns out that the root cause was that PDO doesn't like the cert generated by Google Cloud SQL.