[英]CakePHP 2.0 : Database connection “Mysql” is missing, or could not be created
following the installation of CakePHP 2.0 (modified, I said that I get the same problem on a clean install of cakephp 2.0) I found myself facing an error I have not been able to solve. 在安装CakePHP 2.0之后(修改过,我说我在cakephp 2.0的干净安装上遇到了同样的问题)我发现自己面临一个我无法解决的错误。
configuration: 组态:
server : debian weezy 7 服务器 :debian weezy 7
user : test 用户 :测试
structure : /wwwjail/siteroot/test/htdocs/[app/...] 结构 :/ wwwjail / siteroot / test / htdocs / [app / ...]
nginx configuration nginx配置
cat /etc/nginx/sites-available/test cat / etc / nginx / sites-available / test
server {
listen IP:80 default;
server_name domain.fr;
access_log /var/log/nginx/test.access.log;
error_log /var/log/nginx/test.error.log;
autoindex off;
index index.php index.html;
root /wwwjail/siteroot/test/htdocs/;
location ~ \.php$ {
try_files $uri =404;
fastcgi_intercept_errors on;
fastcgi_pass unix:/wwwjail/siteroot/test/php-fpm.sock;
include /etc/nginx/fastcgi_params;
fastcgi_param SCRIPT_FILENAME $fastcgi_script_name;
}
}
php5-fpm configuration php5-fpm配置
cat /etc/php5/fpm/pool.d/test.conf cat /etc/php5/fpm/pool.d/test.conf
[test]
listen = /wwwjail/siteroot/test/php-fpm.sock
chroot = /wwwjail/siteroot/test/htdocs
user = test
group = test
listen.allowed_clients = 127.0.0.1
listen.owner = test
listen.group = test
listen.backlog = -1
pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
pm.max_requests = 200
pm.status_path = /status_31337
request_terminate_timeout = 30s
catch_workers_output = yes
php_value[session.save_path] = /tmp
Visible errors on the page: 页面上的可见错误:
Database connection "Mysql" is missing, or could not be created.
Error: An Internal Error Has Occurred.
Stack Trace
ROOTlibROOTCakeROOTModelROOTDatasourceROOTDboSource.php line 262 → Mysql->connect()
ROOTlibROOTCakeROOTModelROOTConnectionManager.php line 107 → DboSource->__construct(array)
ROOTlibROOTCakeROOTModelROOTModel.php line 3221 → ConnectionManager::getDataSource(string)
ROOTlibROOTCakeROOTModelROOTModel.php line 1108 → Model->setDataSource(string)
ROOTlibROOTCakeROOTModelROOTModel.php line 3243 → Model->setSource(string)
ROOTlibROOTCakeROOTModelROOTModel.php line 2696 → Model->getDataSource()
ROOTappROOTControllerROOTAppController.php line 70 → Model->find(string, array)
ROOTappROOTControllerROOTChallengesController.php line 57 → AppController->beforeFilter()
[internal function] → ChallengesController->beforeFilter(CakeEvent)
ROOTlibROOTCakeROOTEventROOTCakeEventManager.php line 248 → call_user_func(array, CakeEvent)
ROOTlibROOTCakeROOTControllerROOTController.php line 670 → CakeEventManager->dispatch(CakeEvent)
ROOTlibROOTCakeROOTRoutingROOTDispatcher.php line 184 → Controller->startupProcess()
ROOTlibROOTCakeROOTRoutingROOTDispatcher.php line 162 → Dispatcher->_invoke(ChallengesController, CakeRequest, CakeResponse)
ROOTappROOTwebrootROOTindex.php line 109 → Dispatcher->dispatch(CakeRequest, CakeResponse)
ROOTindex.php line 43 → require(string)
CakePHP: the rapid development php framework
Nginx Error log nginx : Nginx错误日志nginx:
2013/12/24 12:23:03 [error] 17792#0: *535 open() "/wwwjail/siteroot/test/htdocs/css/default.css" failed (2: No such file or directory), client: myIP, server: domain.fr, request: "GET /css/default.css HTTP/1.1", host: "IP:80", referrer: "http://IP:80/"
2013/12/24 12:23:03 [error] 17792#0: *536 open() "/wwwjail/siteroot/test/htdocs/css/bootstrap.css" failed (2: No such file or directory), client: myIP, server: domain.fr, request: "GET /css/bootstrap.css HTTP/1.1", host: "IP:80", referrer: "http://IP:80/"
2013/12/24 12:23:03 [error] 17792#0: *537 open() "/wwwjail/siteroot/test/htdocs/css/jqplot.css" failed (2: No such file or directory), client: myIP, server: domain.fr, request: "GET /css/jqplot.css HTTP/1.1", host: "IP:80", referrer: "http://IP:80/"
2013/12/24 12:23:03 [error] 17792#0: *538 open() "/wwwjail/siteroot/test/htdocs/js/jqplot.js" failed (2: No such file or directory), client: myIP, server: domain.fr, request: "GET /js/jqplot.js HTTP/1.1", host: "IP:80", referrer: "http://IP:80/"
2013/12/24 12:23:03 [error] 17792#0: *534 open() "/wwwjail/siteroot/test/htdocs/js/holder.js" failed (2: No such file or directory), client: myIP, server: domain.fr, request: "GET /js/holder.js HTTP/1.1", host: "IP:80", referrer: "http://IP:80/"
2013/12/24 12:23:03 [error] 17792#0: *531 open() "/wwwjail/siteroot/test/htdocs/css/cake.generic.css" failed (2: No such file or directory), client: myIP, server: domain.fr, request: "GET /css/cake.generic.css HTTP/1.1", host: "IP:80", referrer: "http://IP:80/"
2013/12/24 12:23:03 [error] 17792#0: *531 open() "/wwwjail/siteroot/test/htdocs/img/cake.power.gif" failed (2: No such file or directory), client: myIP, server: domain.fr, request: "GET /img/cake.power.gif HTTP/1.1", host: "IP:80", referrer: "http://IP:80/"
2013/12/24 12:23:03 [error] 17792#0: *535 open() "/wwwjail/siteroot/test/htdocs/js/jqplot.js" failed (2: No such file or directory), client: myIP, server: domain.fr, request: "GET /js/jqplot.js HTTP/1.1", host: "IP:80", referrer: "http://IP:80/"
2013/12/24 12:23:03 [error] 17792#0: *531 open() "/wwwjail/siteroot/test/htdocs/js/holder.js" failed (2: No such file or directory), client: myIP, server: domain.fr, request: "GET /js/holder.js HTTP/1.1", host: "IP:80", referrer: "http://IP:80/"
2013/12/24 12:23:03 [error] 17792#0: *531 open() "/wwwjail/siteroot/test/htdocs/css/cake.generic.css" failed (2: No such file or directory), client: myIP, server: domain.fr, request: "GET /css/cake.generic.css HTTP/1.1", host: "IP:80", referrer: "http://IP:80/"
2013/12/24 12:23:03 [error] 17792#0: *531 open() "/wwwjail/siteroot/test/htdocs/img/cake.power.gif" failed (2: No such file or directory), client: myIP, server: domain.fr, request: "GET /img/cake.power.gif HTTP/1.1", host: "IP:80", referrer: "http://IP:80/"
On the mysql database credentials are correct , the user mysql user-test exist and full access to test.* 在mysql数据库凭据是正确的 ,用户mysql用户测试存在并完全访问测试。*
cat /wwwjail/siteroot/test/htdocs/app/Config/database.php cat /wwwjail/siteroot/test/htdocs/app/Config/database.php
class DATABASE_CONFIG {
public $default = array(
'datasource' => 'Database/Mysql',
'persistent' => false,
'host' => '127.0.0.1',
'login' => 'user-test',
'password' => 'mypassword',
'database' => 'test',
'prefix' => '',
'encoding' => 'utf8'
);
}
Checking the connection with the config file of CakePHP (script found on stackoverflow) 检查与CakePHP的配置文件的连接(在stackoverflow上找到的脚本)
<?php
include("app/Config/database.php");
$config= new DATABASE_CONFIG();
$name = 'default';
$settings=$config->{$name};
$dsn = 'mysql:dbname='.$settings['database'].';host='.$settings['host'];
$user = $settings['login'];
$password = $settings['password'];
try {
$dbh = new PDO($dsn, $user, $password);
echo "Connection succeeded with dsn: ". $dsn . "\n";
$sql = 'SELECT id, title FROM posts';
echo "Here is the contents of the table `posts:";
foreach ($dbh->query($sql) as $row) {
print $row['id'] . "\t" . $row['title'] . "\n";
}
} catch (PDOException $e) {
echo 'PDO error: ' . $e->getMessage();
}
?>
====> return: Connection succeeded with dsn: mysql:dbname=test;host=127.0.0.1 Here is the contents of the table
posts:` ====> return:
Connection succeeded with dsn: mysql:dbname=test;host=127.0.0.1 Here is the contents of the table
帖子Connection succeeded with dsn: mysql:dbname=test;host=127.0.0.1 Here is the contents of the table
:`
Checking socket with php.ini 用php.ini检查套接字
*grep -i 'default_socket' /etc/php5/fpm/php.ini* * grep -i'default_socket'/etc/php5/fpm/php.ini*
default_socket_timeout = 60
pdo_mysql.default_socket= /wwwjail/var/run/mysqld/mysqld.sock
mysql.default_socket = /wwwjail/var/run/mysqld/mysqld.sock
mysqli.default_socket = /wwwjail/var/run/mysqld/mysqld.sock
Verification of the existence of the PDO extension. 验证PDO扩展的存在。
var_dump( extension_loaded('pdo_mysql') );
return => bool(true) return => bool(true)
I hope I have provided much information about my problem. 我希望我提供了很多关于我的问题的信息。 I am willing to perform various manipulations to test.
我愿意进行各种操作来测试。 (I think a problem server side configuration necessarily, although this configuration works for other basic applications connecting to mysql also).
(我认为问题服务器端配置必然,虽然这个配置适用于连接到mysql的其他基本应用程序)。
Sincerely. 真诚。
In your /app/Config/database.php file, change the following line: 在/app/Config/database.php文件中,更改以下行:
'host' => 'localhost',
to: 至:
'host' => '127.0.0.1',
In case you haven't solved this yet: I had the same error in my ubuntu 13.10 machine with the newest xampp downloaded directly from apachefriends. 如果你还没有解决这个问题:我的ubuntu 13.10机器中出现了同样的错误,最新的xampp是直接从apachefriends下载的。 Try this:
尝试这个:
Find your mysql.sock: 找到你的mysql.sock:
user@host /opt$ find . -name mysql.sock
/opt/lampp/var/mysql/mysql.sock
add it to your cakePHP database configuration file (cakePHP)/app/Config/database.php 将它添加到cakePHP数据库配置文件(cakePHP)/app/Config/database.php
'unix_socket' => '/opt/lampp/var/mysql/mysql.sock'
To me, this finally resulted in my cake commands being able to be executed without the " Error: Database connection "Mysql" is missing, or could not be created. ". 对我来说,这最终导致我的蛋糕命令能够执行而没有“ 错误:数据库连接”Mysql“丢失,或无法创建。 ”。
In database.php you need to create a variable array for test database like so: 在database.php中,您需要为测试数据库创建一个变量数组,如下所示:
public $test = array(
'datasource' => 'Database/Mysql',
'persistent' => false,
'host' => 'localhost',
'login' => 'root', // what ever you have as user
'password' => '', // what ever you have as pass
'database' => 'test',
'prefix' => '',
'encoding' => 'utf8',
);
Then crucially make sure you have an empty database called: 然后至关重要的是确保您有一个名为的空数据库:
test
That error message is quite deceiving should really say "Missing database test" :) well in my case this was the issue. 该错误信息是非常欺骗应该真的说“缺少数据库测试”:)在我的情况下这是问题。
Try this and make sure you are using correct username and password 试试这个并确保使用正确的用户名和密码
public $default = array(
'datasource' => 'Database/Mysql',
'persistent' => false,
'host' => 'localhost',
'login' => 'user-test',
'password' => 'mypassword',
'database' => 'test',
'prefix' => '',
'encoding' => 'utf8'
);
Create connection credentials to mysql via phpmyadmin if its set to be empty. 如果设置为空,则通过phpmyadmin创建到mysql的连接凭据。 That worked for me
这对我有用
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.