Laravel无法连接到数据库 [英] Laravel can't connect to DB
问题描述
我正在按照快速入门指南进行操作,并实际进入了本节.连接到数据库以获取用户表,并出现以下错误:
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]用户'root'@'localhost'的访问被拒绝(使用密码:NO)
SQLSTATE[28000] [1045] Access denied for user 'root'@'localhost' (using password: NO)
我的database.php
包括以下设置(默认设置为mysql):
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' => '',
),
但是,当我进入终端窗口时,我可以使用mysql -h localhost -u root -p
登录,然后只需按Enter即可进入而无需输入密码,我认为这是等效的(当出现以下情况时会显示"bt"表我运行show databases();
).我在这里想念什么?
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?
推荐答案
我认为这是解决方案:)
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
这篇关于Laravel无法连接到数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!