PDO connection error when using symfony and MAMP

Getting PDO error while trying to do php symfony doctrine:insert-sql
The error I get is:

 Warning: PDO :: __ construct (): [2002] Connection refused (trying to connect via tcp: //127.0.0.1: 3306) in / Users / johannes / Programmering / PHP / htdocs / symfony / sfprojects / lib / vendor / symfony /lib/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Connection.php on line 470

databases.yml

     all:
     doctrine:
     class: sfDoctrineDatabase
     param:
       dsn: mysql: host = 127.0.0.1; dbname = jobeet;
       username: root
       password: root

Running mysql -u root -p jobeet with "root" as a password gives me access, so there is no problem. And yes, the mysql I'm running is MAMP.

Thanks for any help.

+11
php mysql mamp symfony1 doctrine
Jan 24 '11 at 19:17
source share
4 answers

MAMP does not allow TCP connections by default. You can enable it or use sockets.

Changing your dsn as @Tom suggestions should fix your problems. Be that as it may, but using localhost instead of 127.0.0.1 , this mysql connects through sockets.

http://dev.mysql.com/doc/refman/5.0/en/connecting.html :

On Unix, MySQL programs process the host name localhost specifically, in some ways this is probably different from what you would expect compared to other network programs. To connect to localhost, MySQL programs try to connect to the local server using the Unix socket file. This happens even if the -port or -P option is provided specify the port number. To ensure that the client creates a TCP / IP connection to the local server, use -host or -h to specify the host name 127.0.0.1, or the IP address or name of the local server. You can also specify the connection protocol explicitly, even for the local one using the --protocol = TCP option.

+7
Jan 25 '11 at 9:29
source share

MAMP PRO 2.x
I was able to solve this and many similar problems by simply unchecking the "Allow only local access" checkbox in MySQL prefs in the MAMP control panel.

enter image description here

MAMP PRO 3.x
As indicated by Kendrick : enter image description here

+13
Aug 27 2018-12-12T00:
source share

I had the same error while trying to create my tables in Symfony and use MAMP. I fixed the problem by changing the dsn line in the databases.yml file to the following:

 dsn: 'mysql:host=localhost;dbname=jobeet;unix_socket=/Applications/MAMP/tmp/mysql/mysql.sock' 
+3
May 17 '11 at
source share

It looks right. Here will be the exact equivalent from the working .yml databases that I use if using it:

 dsn: 'mysql:host=localhost;dbname=jobeet' 
+1
Jan 24 '11 at 23:52
source share



All Articles