I have a Webapp which is using the CakePHP 2.x framework. The main front-end works perfectly fine but I have some cron jobs which are run form the Cake Console. When I run these cron jobs I get the following error:
"Error: Database connection “Mysql” is missing, or could not be created"
There are several similar questions on SO (but none of the given solutions works for me. I have the following DB connection setup in the Cake config file and which works for the front-end:
public $default = array(
'datasource' => 'Database/Mysql',
'persistent' => false,
'host' => 'xxxxx.com',
'login' => 'xxxxxx',
'password' => 'xxxxxxx',
'database' => 'goalarc-dev',
'prefix' => '',
'unix_socket' => '/var/run/mysqld/mysqld.sock'
);
I added the 'unix_socket' key after reading a similar solution. My server is running on AWS and so I opened:
/etc/mysql/my.cnf
And found the socket line as follows:
socket = /var/run/mysqld/mysqld.sock
However when I browse to 'var/run/mysqld' the folder is empty when I use the command "ls -l". This would suggest to me that somethig is mis-configured. How can I find the true and valid location of mysql.sock?
A.
Related
I have installed cakephp 2.7.5 on xampp but when I run my application I get an error message >CakePHP is NOT able to connect to the database.
Database connection "Mysql" is missing, or could not be created.< I suspect that my mysql server is not properly configured and I have particular concerns over the PDO and pdo_mysql settings in the php.ini file. How do I enable them? (I am totally lost here)Thanks in advance.
You don't mention configuring the connection, so your problem is most probably that of a missing initial database configuration.
You will obviously need to create a database (and maybe a user with sufficient permissions in that DB) before you setup the configuration. Don't mess with PDO configuration in php.ini, it should run out of the box with XAMPP.
Rename file name from database.php.default to database.php .Create a database in mysql. Open the file and change your mysql login,password and database from default variable.Then run your application.
public $default = array(
'datasource' => 'Database/Mysql',
'persistent' => false,
'host' => 'localhost',
'login' => 'user',
'password' => 'password',
'database' => 'database_name',
'prefix' => '',
//'encoding' => 'utf8',
);
I moved an application that I'm working on into a new dev server, a Laravel Homestead VagrantBox on a Mac OSX host. Upon doing so, I ran php artisan:migrate to update my database and this went through without a hitch.
I decided to create a new user to continue testing, so I created the route
Route::get('/newuser', function()
{
User::create([
'username' => 'someone',
'email' => 'someone#someone.com',
'password' => Hash::make('password')
]);
return 'Done.';
});
When I visit /newuser, however. I am getting the following message.
SQLSTATE[HY000] [2002] Connection refused
Now, I know that my database config must be correct, as I received no errors when I ran php artisan migrate and my database migrated successfully. However, just to be safe, I checked my database config.
'mysql' => array(
'driver' => 'mysql',
'host' => 'localhost:33060',
'database' => 'site',
'username' => 'root',
'password' => 'apassword',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
),
I figured that maybe there was an issue with the way I defined the port I was on, so I added the parameter:
'port' => '33060'
Upon doing this, the error message changed from "Connection refused" to "No such file or directory"
I'm at a loss. Does anyone have any pointers?
Now, I know that my database config must be correct, as I received no errors when I ran php artisan migrate
It's a better than even money bet when you're stuck on something that it's one of your assumptions that's the problem. It's possible your Laravel application is reading different credentials during a command line run, or that the migration had nothing to do, or for some weird PHP reason the errors were suppressed during your migration run. I'd check the credentials Laravel's using during the context your errors are cropping up. Add the following code to your newuser route to see what Laravel's reading.
$default = Config::get('database.default');
var_dump($default);
$config = Config::get('database.connections.'.$default);
var_dump($config);
I had same problem and i saw my database server was unresponsive i restarted and it works... sometime it cause when wrong configuration.
I posted this answer if someone will have same issue and mysql unresponsive :)
I have scoured the web for an answer but as of now have been unsuccessful. I am attempting to connect CakePHP to a database. But I keep getting the same response:
CakePHP is NOT able to connect to the database.
Database connection "Mysql" is missing, or could not be created.
Here is part of my database.php file
public $default = array(
'datasource' => 'Database/Mysql',
'persistent' => false,
'host' => 'localhost',
'login' => 'root',
'password' => '',
'database' => 'cake',
'prefix' => '',
//'encoding' => 'utf8',
);
^I've also tried different host/login combinations based from the access privileges list in phpmyadmin.
I think one problem might be that Wampserver is finding the wrong php.ini file. It seems that it is loading the file at: "C:\Program Files (x86)\PHP\php.ini" instead of something under "C:\wamp...". How would I set it to point at the right file??
However, I had added the line "extension=php_pdo_mysql.dll" to both files and still no luck. Any help would be appreciated.
I had the exact same issue. There was no problem in the mysql database as it was accessible through phpMyadmin and other applications running on the server. The issue was caused due to the mysql port not mentioned alongwith the host. Append the port with the host like... 'host' => 'localhost:3307'.
public $default = array(
'datasource' => 'Database/Mysql',
'persistent' => false,
'host' => 'localhost:3307',
'login' => 'root',
'password' => 'mypass',
'database' => 'cake_todos',
'prefix' => '',
//'encoding' => 'utf8',
);
Now, how to know the mysql port? For that you need to go to the server configuration file.. e.g. the in my case it was the properties.ini file in the home directory of the wamp folder. Open the file and you will most probably find an entry like this:
mysql_port=3307
mysql_host=127.0.0.1
So, here it is, the mysql_port. Hope it helps.
First check there is database called cake in your localhost/phpmyadmin, and if that mysql use the username root and no password and also make sure you set php_mysql on the right php.ini file (extension=php_mysql.dll).
Second, if you think the problem is because of php.ini file location, you can set it:
go to your wamp folder (C:\wamp) and
under that folder you'll find wampmanager.ini file and
Find php.ini word in that file you'll get this kind of line
(Type: item; Caption: "php.ini"; Glyph: 6; Action: run; FileName: "notepad.exe"; parameters: "...path here...")and locate the path and set "C:/wamp/bin/apache/apache2.2.21/bin/php.ini"
please tell me (vote) if it works. I hope it helps.
Thanks
I'm developing on XAMPP 1.8.1 and running into issues with CakePHP not being able to connect to the database. I've looked around a bit, and others have suggested making sure pdo is enabled, and it is. I know my database settings are correct. I've checked and rechecked them, but I'm still getting:
Cake is NOT able to connect to the database.
Database connection "Mysql" is missing, or could not be created.
I've set up CakePHP multiple times before, even with XAMPP, and I've never run into this issue.
My database settings are as follows:
public $default = array(
'datasource' => 'Database/MySQL',
'persistent' => false,
'host' => 'localhost',
'login' => 'cakeuser',
'password' => '*****',
'database' => 'cake',
'prefix' => '',
//'encoding' => 'utf8',
);
Any suggestions?
Check the output of your phpinfo (). Is there a row titled PDO drivers? What does it say?
beginner level stuff-
-i recently hosted my cakephp project on 000webhost.com
-it shows the cake homepage
-but at the same time shows
Cake is NOT able to connect to the database.
Datasource class a2952772 could not be found.
-i have tried editing root/app/config/database.php number of times.
-i have created mysql database on 000webhost.com
i guess there is some problem with
$datasource in
public $default = array(
'datasource' => '????',
'persistent' => false,
'host' => 'mysql11.000webhost.com',
'login' => '*****',
'password' => '*****',
'database' => 'db1',
'prefix' => '',
//'encoding' => 'utf8',
);
if anybody has hosted and configured databases on 000webhost.com ,plz help...
You need to specify a valid datasource, such as 'Database/Mysql'. Also check the CakePHP database configuration section.