Laravel 5.1-连接到MySQL数据库(MAMP) [英] Laravel 5.1 - Connecting to MySQL Database (MAMP)

查看:150
本文介绍了Laravel 5.1-连接到MySQL数据库(MAMP)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在线上有讨论此问题的主题,但是我找不到关于该问题的任何整洁的解释或该问题的可靠答案.我想要实现的是将Laravel 5.1连接到MAMP的MySQL数据库.

There are topics online that are discussing this problem however, I couldn't find any tidy explanation of the problem or any solid answers for the question. What I am trying to achieve is connecting Laravel 5.1 to MySQL Database of MAMP.

在我的 config> app.php中:

In my config>app.php:

   'default' => env('DB_CONNECTION', 'mysql'),


   'mysql' => [
        'driver'    => 'mysql',
        'host'      => 'localhost:8889',
        'database'  => 'test',
        'username'  => 'root',
        'password'  => 'root',
        'charset'   => 'utf8',
        'collation' => 'utf8_unicode_ci',
        'unix_socket'   => '/Applications/MAMP/tmp/mysql/mysql.sock',
        'prefix'    => '',
        'strict'    => false,
    ],

在我的 .env中:

In my .env:

      DB_HOST=localhost
      DB_DATABASE=test
      DB_USERNAME=root
      DB_PASSWORD=root

我也有 .env.example: (我认为它没有功能)

I also have .env.example: (which I believe has no functionality)

      DB_HOST=localhost
      DB_DATABASE=homestead
      DB_USERNAME=homestead
      DB_PASSWORD=secret

我的 database>迁移 中也有create_users_table.phpcreate_password_resets_table.php(即使我没有运行任何迁移:make)

I also have create_users_table.php and create_password_resets_table.php in my database>migrations (even though I did not run any migration:make)

MAMP在将项目加载到localhost时成功地指导和运行服务器.

MAMP is directing and running the server successfully as it loads the project on localhost.

这是我的MAMP设置:

Here is my MAMP settings:

然后创建了test数据库(其中包含我以前创建并在其他项目(而不是Laravel)中使用的表).

And the test database is created (with tables in it which I have previously created and used in my other projects, not Laravel.)

即使一切对我来说似乎都是正确的,但在尝试提交身份验证表单时,却出现了此错误:

Even though everything seems correct to me, when trying to submit Auth form, I am getting this error:

Connector.php第50行中的

PDOException: 找不到驱动程序

PDOException in Connector.php line 50: could not find driver

  1. 在Connector.php第50行中

  1. in Connector.php line 50

at PDO-> __ construct('mysql:unix_socket =/Applications/MAMP/tmp/mysql/mysql.sock; dbname = test','root','root',array('0',' 2','0',false,false))在Connector.php第50行

at PDO->__construct ('mysql:unix_socket=/Applications/MAMP/tmp/mysql/mysql.sock;dbname=test', 'root', 'root', array('0', '2', '0', false, false)) in Connector.php line 50

at连接器-> createConnection('mysql:unix_socket =/Applications/MAMP/tmp/mysql/mysql.sock; dbname = test',array('driver'=>'mysql','host'= >'localhost:8889','数据库'=>'测试','用户名'=>'根','密码'=>'根','字符集'=>'utf8','归类'=>'utf8_unicode_ci ','unix_socket'=>'/Applications/MAMP/tmp/mysql/mysql.sock','前缀'=>'','严格'=> false,'名称'=>'mysql'),array(' 0','2','0',false,false))在MySqlConnector.php第22行中

at Connector->createConnection('mysql:unix_socket=/Applications/MAMP/tmp/mysql/mysql.sock;dbname=test', array('driver' => 'mysql', 'host' => 'localhost:8889', 'database' => 'test', 'username' => 'root', 'password' => 'root', 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', 'unix_socket' => '/Applications/MAMP/tmp/mysql/mysql.sock', 'prefix' => '', 'strict' => false, 'name' => 'mysql'), array('0', '2', '0', false, false)) in MySqlConnector.php line 22

以此类推...

推荐答案

找到了我的答案.这是一种解决方法:

  • 启动MAMP
  • 在左上角,转到"MAMP"->首选项"
  • 转到"PHP"标签
  • 勾选PHP 5.5.17(或您拥有的任何东西),而不是默认选中的PHP版本(5.6.1-> 5.5.17(使用最新版本的MAMP))

这篇关于Laravel 5.1-连接到MySQL数据库(MAMP)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆