运行 `php app/console 指令:schema:create` 时对“没有这样的文件或目录”进行故障排除
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6259424/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Troubleshooting "No such file or directory" when running `php app/console doctrine:schema:create`
提问by LBridge
I am new to Symfony2 (beta4) and Doctrine and am having issues when i try to create the DB schema via command line.
我是 Symfony2 (beta4) 和 Doctrine 的新手,当我尝试通过命令行创建 DB 模式时遇到了问题。
Here's the error:
这是错误:
$ php app/console doctrine:schema:create
Creating database schema...
[PDOException]
SQLSTATE[HY000] [2002] No such file or directory
[ErrorException]
Warning: PDO::__construct(): [2002] No such file or directory (trying to connect via unix:///var/mysql/mysql.sock)
in /Applications/MAMP/htdocs/sf-test-2/vendor/doctrine-dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php line 36
The mysql database settings are correctly inserted in the config/parameters.ini file.
mysql 数据库设置正确插入到 config/parameters.ini 文件中。
And here's the Doctrine configuration in config.yml
这是 config.yml 中的 Doctrine 配置
# Doctrine Configuration
doctrine:
dbal:
driver: %database_driver%
host: %database_host%
dbname: %database_name%
user: %database_user%
password: %database_password%
orm:
auto_generate_proxy_classes: %kernel.debug%
auto_mapping: true
And the entity (i made only one to test it)
和实体(我只做了一个来测试它)
<?php
// src/Acme/NewsBundle/Entity/Article.php
namespace Acme\NewsBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
* @ORM\Table(name="articles")
*/
class Article
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\Column(type="string", length="255")
*/
protected $title;
/**
* @ORM\Column(type="text")
*/
protected $body;
/**
* @ORM\Column(type="string", length="255")
*/
protected $author;
/**
* @ORM\Column(type="date")
*/
protected $date;
}
?>
采纳答案by LBridge
I fixed it by following this small tutorial: http://andreys.info/blog/2007-11-07/configuring-terminal-to-work-with-mamp-mysql-on-leopard
我按照这个小教程修复了它:http: //andreys.info/blog/2007-11-07/configuring-terminal-to-work-with-mamp-mysql-on-leopard
[EDIT]: I modified the right php.ini and everything's working fine now.
[编辑]:我修改了正确的 php.ini,现在一切正常。
Now I get the following error:
现在我收到以下错误:
[Exception]
DateTime::__construct(): It is not safe to rely on the system's timezone settings.
You are *required* to use the date.timezone setting or the date_default_timezone_set() function.
In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier.
We selected 'Europe/Berlin' for 'CEST/2.0/DST' instead
Here's the date.timezone config in php.ini
这是 php.ini 中的 date.timezone 配置
date.timezone = "Europe/Paris"
I'll try to figure it out myself but if any of you know how to fix it don't hesitate to comment on this. Thanks!
我会尝试自己弄清楚,但如果你们中的任何人知道如何解决它,请不要犹豫,对此发表评论。谢谢!
回答by EricSonaron
Too late but I hope it can help someone.
为时已晚,但我希望它可以帮助某人。
Just today I fall into a similar situation (but in other context, I was trying to create entities from db).
就在今天,我陷入了类似的情况(但在其他情况下,我试图从 db 创建实体)。
I solved it simply modifying de database_host from "localhost" to "127.0.0.1" in the parameters.ini file.
我解决了它,只需在 parameters.ini 文件中将 de database_host 从“localhost”修改为“127.0.0.1”即可。
I think my Mysql instance is running only via TCP and not socket and because this when use database_host="localhost" it fails.
我认为我的 Mysql 实例仅通过 TCP 而不是套接字运行,因为当使用 database_host="localhost" 时它会失败。
回答by Saperlipopette
Try to add this line
尝试添加这一行
unix_socket: /tmp/mysql.sock
into your config.yml file > doctrine > dbal just after the password line.
进入你的 config.yml 文件 > 教义 > dbal 就在密码行之后。
回答by victormfv
I changed 'host'=> 'localhost' to 'host'=> '127.0.0.1' on app/config/database.php and everything is working correctly
我在 app/config/database.php 上将 'host'=> 'localhost' 更改为 'host'=> '127.0.0.1' 并且一切正常
回答by Justin
The problem for me was the mysql.default_socket
setting in PHP.INI defaults to a different location than where MySQL actually puts that file.
我的问题是mysql.default_socket
PHP.INI 中的设置默认为与 MySQL 实际放置该文件的位置不同的位置。
Instead of editing the config files, I created an alias in the location that PHP is looking that connects to the real mysql.sock.
我没有编辑配置文件,而是在 PHP 查找的连接到真实 mysql.sock 的位置创建了一个别名。
Just run these two commands (no restart needed):
只需运行这两个命令(无需重启):
mkdir /var/mysql
ln -s /tmp/mysql.sock /var/mysql/mysql.sock
回答by Mehedi Hasan
Sometimes you may got several solution for location path of mysql.lock. But I think the best solution is just see the location path of mysql using php phpinfo()
function.
有时你可能会得到几种解决 mysql.lock 位置路径的方法。但我认为最好的解决方案是使用phpphpinfo()
函数查看mysql的位置路径。
Note: if you are not familar with phpinfo()
, then just create a file give any name and include content of that file like this
注意:如果您不熟悉phpinfo()
,那么只需创建一个文件,给出任何名称并像这样包含该文件的内容
<?php
phpinfo();
?>
run this file and get the path of mysql.lock file. I think it will help.
运行此文件并获取mysql.lock 文件的路径。我认为它会有所帮助。
回答by Isaac
Worth checking to see if Mysql is running too.
值得检查一下 Mysql 是否也在运行。
回答by Fabio Valencio
Too late but hope it can help someone as well.
为时已晚,但希望它也可以帮助某人。
I am using Vagrant
我正在使用流浪者
Just change localhost
to 127.0.0.1
AND change the port to 3333
只需更改localhost
为127.0.0.1
并将端口更改为3333
worked perfectly.
完美地工作。
回答by Reyno D'Wolfer
I think just restart the mysql, and apache, that's work for me.
我认为只需重新启动 mysql 和 apache,这对我有用。
回答by Geoffrey Hale
Restarting mysql worked for me:
重新启动 mysql 对我有用:
sudo /etc/init.d/mysql restart
sudo /etc/init.d/mysql restart