Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
528 views
in Technique[技术] by (71.8m points)

mysql - Troubleshooting "No such file or directory" when running `php app/console doctrine:schema:create`

I am new to Symfony2 (beta4) and Doctrine and am having issues when i try to create the DB schema via command line.

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.

And here's the Doctrine configuration in config.yml

# 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 AcmeNewsBundleEntity;

use DoctrineORMMapping as ORM;

/**
 * @ORMEntity
 * @ORMTable(name="articles")
 */
class Article
{
    /**
     * @ORMId
     * @ORMColumn(type="integer")
     * @ORMGeneratedValue(strategy="AUTO")
     */
protected $id;

/**
 * @ORMColumn(type="string", length="255")
 */
protected $title;

/**
 * @ORMColumn(type="text")
 */
protected $body;

/**
 * @ORMColumn(type="string", length="255")
 */
protected $author;

/**
 * @ORMColumn(type="date")
 */
protected $date;
}
?>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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).

I solved it simply modifying de database_host from "localhost" to "127.0.0.1" in the parameters.ini file.

I think my Mysql instance is running only via TCP and not socket and because this when use database_host="localhost" it fails.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...