How to connect a Laravel app to MySQL using MAMP?

2019-02-05 07:09发布

问题:

SOLVED: I followed what this website said http://forums.laravel.io/viewtopic.php?id=980 I just added 'unix_socket' to the mysql array and it worked!

I am following the Laravel quick start guide at http://laravel.com/docs/quick

I have everything set up and am using MAMP. When I try and view the /public/users page, I am hit with:

PDOException

SQLSTATE[28000] [1045] Access denied for user 'root'@'localhost' (using password: YES)" error.

My database.php file looks like so:

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

My MAMP displays:

host        localhost
port        8889
user        root
password    root

My question is, is the MySQL on MAMP's separate from the MySQL tables I have created locally? I am assuming yes because I am not able to see the tables on PHPMyAdmin. If so, is there a way to connect my Laravel app to MAMP's MySQL?

回答1:

MAMPs MySQL is running on port 8889, so add 'port' => '8889' to your config array