Home  >  Q&A  >  body text

mysql - 有关laravel链接数据库的问题

用laravel4.2写了个项目,在本地做测试的时候是没有问题的
然后现在把项目搬到阿里云上之后 使用

php artisan migrate

显示

SQLSTATE[28000] [1045] Access denied for user 'root'@'XXXXXXXX' (using password: YES)

用户名和密码是正确的 因为通过

mysql -uroot -p

可以登录
下面是我的代码

'mysql' => array(

        'driver'    => 'mysql',

        'host'      => 'XXX.XXX.XXX.XXX',

        'database'  => 'sing',

        'username'  => 'root',

        'password'  => 'XXXXX',

        'charset'   => 'utf8',

        'collation' => 'utf8_unicode_ci',

        'prefix'    => '',

    ),

所以想请问一下 出现这样的问题的话怎么解决

PHPzPHPz2743 days ago687

reply all(2)I'll reply

  • 迷茫

    迷茫2017-04-17 12:08:56

    If you are accessing the database locally
    Put
    'host' => 'XXX.XXX.XXX.XXX',
    Change to
    'host' => 'localhost' or 'host' => '127.0.0.1'
    If the database is called remotely.
    Then you need to add remote calling permissions to the user. Please refer to Baidu

    for specific operations.

    reply
    0
  • 黄舟

    黄舟2017-04-17 12:08:56

    mysql -uroot -p
    Add the -h parameter to this command (corresponding to the host configuration in laravel) to see if it can still be connected.

    reply
    0
  • Cancelreply