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

编程入门 行业动态 更新时间:2024-10-26 22:26:53
本文介绍了SQLSTATE[HY000] [2003] Can't connect to MySQL server on '127.0.0.1' (61) error Laravel 4.1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在 Laravel 4.1(使用 MAMP)的本地主机上收到以下错误

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)

它指向:

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

这是它指向的函数:

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

在 config/local/database.php 我有:

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' => '', ),

推荐答案

这样的错误意味着服务器本身甚至无法访问.您是否在 MAMP 中启动了 MySQL?

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

另外,您是如何开始 MAMP 的?使用标准 MySQL 3306 端口?或者 MAMP 用于非管理员的替代端口:8889?

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

我打赌您的服务器正在运行,但正在尝试连接到 3306,因此您需要将端口设置为 8889.将您的配置更改为这样;注意添加 port 参数:

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' => '', ),

我刚刚发现 this question thread 解决了通过端口 8889 将 Laravel 连接到 MAMP 的问题.

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

更多推荐

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

本文发布于:2023-10-26 01:20:39,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1528662.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:connect   MySQL   SQLSTATE   server   error

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!