Doctrine 2 command line tool; MAMP and mysql.sock

送分小仙女□ 提交于 2020-01-01 07:21:34

问题


I grabbed the CI2/Doctrine2 from Wildly Inaccurate. I'm trying to start using it, but before I'm actually getting to work with it, I wanted to make sure everything works. However, when I try the command line tool, I run into the following error:

$ ./doctrine orm:schema-tool:create

ATTENTION: This operation should not be executed in a production environment.

Creating database schema...

Warning: PDO::__construct(): [2002] Socket operation on non-socket (trying to connect via unix:///var/mysql/mysql.sock) in /Users/joris/Desktop/ci2_starter/application/libraries/Doctrine/DBAL/Driver/PDOConnection.php on line 36



  [PDOException]                                         
  SQLSTATE[HY000] [2002] Socket operation on non-socket  



orm:schema-tool:create [--dump-sql]

I'm running this on a cleanly installed MAMP Pro 2.0.1; I'm not really sure what to do to fix this error.. I'm not really knowledgeable on the inner (background) workings of MySQL. Could someone clear this up for me? Thanks a lot.

Update:

MacBook-Pro-van-Joris-Ooms:~ joris$ sudo find / -name 'mysql.sock'
Password:
/Applications/MAMP/tmp/mysql/mysql.sock
find: /dev/fd/3: Not a directory
find: /dev/fd/4: Not a directory
/private/var/mysql/mysql.sock
/private/var/mysql/mysql.sock/mysql.sock

回答1:


MAMP does use it's own mysql socket while the CLi uses the default one in /var/mysql/mysql.sock. This could mean you are running the wrong PHP version (not the MAMP one but the default MAC OS X one). Not a big deal since it can deal with your Doctrine Command Line Issues as well. So you do have several options:

  1. try using the MAMP php version to start the CLi tool by putting the Path to your MAC OS X php version as a prefix i.e.

    /Applications/MAMP/bin/php5.3/bin/php ./doctrine orm:schema-tool:create

  2. just set up a link from /var/mysql/mysql.sock to the actual Socket file which should be in /Applications/MAMP//tmp/mysql/mysql.sock So you go to the terminal while your MAMP is running an type (You will be asked to type in a password):

    sudo ln -s /Applications/MAMP//tmp/mysql/mysql.sock /var/mysql/mysql.sock

  3. Find every occurrence of "/Applications/MAMP//tmp/mysql/mysql.sock" in any of your MAMP config files and change it to be /var/mysql/mysql.sock so you actually do use the default address for MySQL Socket. Though, i have never tested if this does work.



来源:https://stackoverflow.com/questions/7461360/doctrine-2-command-line-tool-mamp-and-mysql-sock

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!