简体   繁体   中英

PDO Exception with Laravel 4 php artisan migrate command on EC2 AWS

I have an ubuntu 12.04 instance on EC2 in AWS and a Laravel 4 Project uploaded there. I am trying to run php artisan migrate, but for some reason I cannot connect to my mysql server through the command. I am able to get into the MySql DB on SQL Pro just find using SSH (using the elastic ip as host). I also SSH into the server using Elastic IP.

I get this error when I run php artisan migrate:

[PDOException]                                                               
  SQLSTATE[HY000] [2003] Can't connect to MySQL server on '**.***.***.**' (11  
  1)                                                                           



migrate [--bench[="..."]] [--database[="..."]] [--path[="..."]] [--package[="..."]] [--pretend] [--seed]

Where the starts represent my "elastic IP", which is the host I use to connect to mySQL in SQL Pro.

In my database.php config file, I am connecting using:

'mysql' => array(
            'driver'    => 'mysql',
            'host'      => '*ELASTIC IP*',
            'database'  => 'dbname',
            'username'  => '****',
            'password'  => '*******',
            'charset'   => 'utf8',
            'collation' => 'utf8_unicode_ci',
            'prefix'    => '',
        ),

I have installed php5, apache2, mcrypt, and php5-mysql on this server. How do I solve this issue? Thank you.

Sounds like you are not necessarily allowing your 'user' into the database.

In MySQL the 'user' is a combination of 'username'@'hostname' . It could be that you are just allowing your username for a particular host which could be localhost or 127.0.0.1 . To see if this is the problem you can create a user with the hostname wildcard % . Also, by allowing that user to all databases. From the mysql> command line like this:

CREATE USER '<username>'@'%' IDENTIFIED BY 'your-password';
GRANT ALL PRIVILEGES ON *.* TO '<username>'@'%';

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM