SQLSTATE[HY000] [2003] Can't connect to MySQL server on '127.0.0.1' (61) error Laravel 4.1 [duplicate]

匿名 (未验证) 提交于 2019-12-03 02:48:02

问题:

This question already has an answer here:

I am receiving the following error on my localhost for Laravel 4.1 (using MAMP)

SQLSTATE[HY000] [2003] Can't connect to MySQL server on '127.0.0.1' (61) 

It points to:

/Applications/MAMP/htdocs/crowdsets/laravel-master/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php 

This is the function it is pointing to:

public function createConnection($dsn, array $config, array $options)     {         $username = array_get($config, 'username');          $password = array_get($config, 'password');          return new PDO($dsn, $username, $password, $options);     } 

Up to this point, I had not received this error.

I have a local environment and production environment set up (the default).

in config/local/database.php I have:

'mysql' => array(             'driver'    => 'mysql',             'host'      => '127.0.0.1',             'database'  => 'database',             'username'  => 'root',             'password'  => 'root',             'charset'   => 'utf8',             'collation' => 'utf8_unicode_ci',             'prefix'    => '',         ), 

回答1:

An error like that means the server itself is not even reachable. Did you start MySQL in MAMP?

Also, how have you started MAMP? With the standard MySQL 3306 port? Or the alternative port MAMP uses for non-admins: 8889?

I bet your server is running, but is attempting to connect to 3306 so you need to set the port to 8889. Change your config to be like this; note the addition of the port param:

'mysql' => array(             'driver'    => 'mysql',             'host'      => '127.0.0.1',             'port'      => '8889',             'database'  => 'database',             'username'  => 'root',             'password'  => 'root',             'charset'   => 'utf8',             'collation' => 'utf8_unicode_ci',             'prefix'    => '',         ), 

EDIT: I just found this question thread that addresses the issue of connecting Laravel to MAMP via port 8889.



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