I want to connect to CakePHP3.77 with MySQL 5.7.25 in MAMP.
I cannot connect with database named cake_youtube_db.
Error Message is this.
CakePHP is NOT able to connect to the database.
Connection to database could not be established: SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client
I did try create other users and put user and password.
However they did not work.
/config/app.php
'Datasources' => [
'default' => [
'className' => 'Cake\Database\Connection',
'driver' => 'Cake\Database\Driver\Mysql',
'persistent' => false,
'host' => 'localhost',
//'port' => 'non_standard_port_number',
'username' => 'root',
'password' => 'root',
'database' => 'cake_youtube_db',
SQL plugin is mysql_native_password.
I expect Database will be connected with my cakeapp.
Related
I installed virtualmin on a VM instance using google compute engine. I have set up 1 domain and 1 subdomain. On the subdomain i created a database (flexijobs) and added the Drupal tables. Everything works fine except the connection to the database. On loading the drupal index page i get this error:
PDOException: SQLSTATE[HY000] [2002] Connection timed out
My guess is that the settings are not correct, so in a virtualmin setup, what should i use here, where can i set the password/user, what port should i use, what is the host?
$databases['default']['default'] = array (
'database' => 'flexijobs',
'username' => 'someUsername',
'password' => 'somePassword',
'prefix' => '',
'host' => 'db.somedomain.com',
'port' => '3306',
'namespace' => 'Drupal\\Core\\Database\\Driver\\mysql',
'driver' => 'mysql',
);
Create a new database through Webmin > Servers > MariaDB Database Server
Note the name, username and password for the database you just made and modify the configuration file to include the information for your database.
The host field should be set to localhost
$databases['default']['default'] = array (
'database' => 'database_name',
'username' => 'db_username',
'password' => 'db_password',
'prefix' => '',
'host' => 'localhost',
'port' => '3306',
'namespace' => 'Drupal\\Core\\Database\\Driver\\mysql',
'driver' => 'mysql',
);
'default' => [
'className' => 'Cake\Database\Connection',
'driver' => 'Cake\Database\Driver\Mysql',
'persistent' => false,
'host' => 'localhost',
'username' => 'root',
'password' => '000000',
'database' => 'cakephp',
'encoding' => 'utf8mb4',
'timezone' => 'UTC',
'cacheMetadata' => true,
my database in phpmyadmin in xampp is ok.
But stil the cakephp homepage says
CakePHP is NOT able to connect to the database.
Connection to database could not be established: SQLSTATE[HY000] [1045] Access denied for user 'my_app'#'localhost' (using password: YES)
I recently faced this issue and solved it by adding database configuration in config/app_local.php
As per Cakephp documentation:
The application skeleton features a config/app.php file which should
contain configuration that doesn’t vary across the various
environments your application is deployed in.
The config/app_local.php
file should contain the configuration data that varies between
environments and should be managed by configuration management, or
your deployment tooling
Reference:
CAKEPHP -> Configuration -> Configuring your Application
In my local environment I have working a secondary remote mysql connection specified in config/database.php without any problems:
# Secondary database connection
'mysql_remote' => [
'driver' => 'mysql',
'host' => env('DB_HOST_2', 'cherokee.websitewelcome.com'),
'port' => env('DB_PORT_2', '3306'),
'database' => env('DB_DATABASE_2', 'dbname'),
'username' => env('DB_USERNAME_2', 'dbusr'),
'password' => env('DB_PASSWORD_2', 'dbpass'),
'unix_socket' => env('DB_SOCKET_2', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'strict' => true,
'engine' => null,
],
But when I run this on production server with the exact same database file I get the following error, is like the remote host (cherokee.websitewelcome.com) is not used and replace it with local server host (eu01.server.plus)
SQLSTATE[HY000] [1045] Access denied for user 'dbusr'#'eu01.server.plus' (using password: YES) (SQL: select ...)
Any ideas?
Solved by adding eu01.server.plus to authorized hosts on remote mysql server. Initially I was adding the IP and not hostname.
When I try to login to the app I have setup on Forge, my Laravel app spits out this error:
SQLSTATE[HY000] [1045] Access denied for user 'appname'#'localhost' (using password: YES)
I have the environment variables configured correctly and they work fine on my copy of the site on my local Homestead vagrant box.
Here is the .env.php file that Forge wrote:
return [
'APP_ENV' => 'production',
'DB_DRIVER' => 'mysql',
'DB_HOST' => 'localhost',
'DB_NAME' => 'appname',
'DB_USER' => 'appname',
'DB_PASS' => 'LoNgPaSsWoRd',
];
Here is the relevant contents of app/config/database.php which works locally:
'default' => getenv('DB_DRIVER'),
'connections' => array(
'mysql' => array(
'driver' => getenv('DB_DRIVER'),
'host' => getenv('DB_HOST'),
'database' => getenv('DB_NAME'),
'username' => getenv('DB_USER'),
'password' => getenv('DB_PASS'),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
),
),
I tried dumping the environment values before the first database connection is accessed using dd(getenv('DB_PASS'), getenv('DB_USER')) and they show up correct.
I also tried connecting through MySQL Workbench and resetting the password to exactly what is shown in the environment variable Forge wrote.
None of my other subdomains are having this issue.
What could be going on here and how could I debug this?
I have my Cake app and it's is working on my PC on Apache but it connects to the remote database.
And everything is fine.
But when I copied my app on server, there is an error when I try to execute any controller:
Error: SQLSTATE[HY000] [2005] Unknown MySQL server host 'xx.xx.xx.xx:33306' (2) requires a database connection
Error: Confirm you have created the file : app/Config/database.php.
And I tested the connection in simple php script (on server) and I connect and get data from this database without problem. So why Cake can't connect to it?? What might be problem?
public $external = array(
'datasource' => 'Database/Mysql',
'persistent' => false,
'host' => 'xx.xx.xx.xx:33306',
'login' => 'xxx',
'password' => 'xxx',
'database' => 'xxx',
);
The file 'database.php' exists in app/config and has permissions rwxr-xr-x
I am not sure about mod_rewrite... how I can check it?
'host' => 'xx.xx.xx.xx:33306',
is not allowed. You should use the optional port option as specified in the CakePHP docs.
public $external = array(
'datasource' => 'Database/Mysql',
'persistent' => false,
'host' => 'xx.xx.xx.xx',
'port' => '33306',
'login' => 'xxx',
'password' => 'xxx',
'database' => 'xxx',
);