Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel 5.1 - Connecting to MySQL Database (MAMP)

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.


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,
    ],

In my .env:

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

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

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

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 is directing and running the server successfully as it loads the project on localhost.


Here is my MAMP settings:

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:

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

  1. in Connector.php line 50

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

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

and so on...

like image 493
senty Avatar asked Jul 21 '15 14:07

senty


1 Answers

On mac or unix you have to include the socket path in the configuration database.php file

i.e 'unix_socket' => '/Applications/MAMP/tmp/mysql/mysql.sock',

like image 136
sese smith Avatar answered Oct 05 '22 12:10

sese smith