Laravel can't connect to DB

天涯浪子 提交于 2019-12-10 16:17:28

问题


I'm following through the Quick Start Guide, and got to the section actually connecting to the DB to fetch the users table, and am getting the following error:

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

My database.php includes the following setup (default set to mysql):

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

When I go to the terminal window, however, I'm able to log in using mysql -h localhost -u root -p then just hit enter to go in without a password, which I thought would be equivalent (the 'bt' table shows up when I run show databases();). What am I missing here?


回答1:


I think this is the solution :)

'mysql' => array(
    'driver'    => 'mysql',
    'host'      => '127.0.0.1',
    'database'  => 'bt',
    'username'  => 'root',
    'password'  => '',
    'charset'   => 'utf8',
    'collation' => 'utf8_unicode_ci',
    'prefi



回答2:


It's also possible that pdo is not installed on your machine. You can check if it's installed from the phpinfo() page or a php script

if ( extension_loaded('pdo') ) {
    .......
}

On linux you can install it by

sudo apt-get install php5-mysql


来源:https://stackoverflow.com/questions/20334627/laravel-cant-connect-to-db

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!