php PDOException SQLSTATE[HY000] [1049] 未知数据库“伪造”失败
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28421626/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
PDOException SQLSTATE[HY000] [1049] Unknown database 'forge' failed
提问by Ironheartbj18
I want to access a Mysql data the first step is to create a new table for "vanvlymen" and I typed mysql> USE vanvlymen; the database changed. and type SHOW tables; showing the available of the tables that the database contains.
我想访问一个 Mysql 数据,第一步是为“vanvlymen”创建一个新表,然后输入 mysql> USE vanvlymen; 数据库变了。并键入 SHOW 表;显示数据库包含的可用表。
mysql -u root -p
enter password: ****
mysql> show databases;
-databases-
information_schema
mysql
performance_schema
phpmyadmin
vanvlymen
5 rows...
everything is looking good... I have decide to tell mysql to specify the database I am working on before executing the query as "vanvlymen"
一切看起来都很好......我决定告诉mysql在执行查询之前指定我正在处理的数据库为“vanvlymen”
app/config/database.php
应用程序/配置/数据库.php
'mysql' => array(
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'vanvlymen',
'username' => 'foobar',
'password' => 'foobar',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
),
save as file go to FileZilla using FTP find a file drag and drop into my live server overwrite the database.php file.
另存为文件 使用 FTP 转到 FileZilla 找到一个文件拖放到我的实时服务器中覆盖 database.php 文件。
I have tried to clear the cache like that
我试图像那样清除缓存
php artisan cache:clear
php artisan migrate
it errors:
它错误:
SQLSTATE[42000] [1049] unknown database 'forge'.
Why keeping it said unknown database 'forge' I am excepting to change to vanvlymen database. Should I remove mysql and reinstall?
为什么保持它说未知数据库“伪造”我除了更改为 vanvlymen 数据库。我应该删除mysql并重新安装吗?
I am using windows 8.1 with laravel 4.2
我正在使用带有 Laravel 4.2 的 Windows 8.1
Using phpmyadmin, I know what is the password and username to log in.
使用phpmyadmin,我知道登录的密码和用户名是什么。
采纳答案by Xyrus
Do you have something like app/config/yourEnvironment/database.php ? For example localor production. 'forge' is default name of DB in this config file, so it looks like your app is loading wrong config file.
你有类似 app/config/ yourEnvironment/database.php 的东西吗?例如本地或生产。'forge' 是这个配置文件中数据库的默认名称,所以看起来你的应用加载了错误的配置文件。
回答by Style Left
remove two files config.php
and services.php
in /bootstrap/cache
. And try again.
删除两个文件config.php
并services.php
在/bootstrap/cache
. 然后再试一次。
回答by wired00
Hopefully this will help someone else. I suddenly had an issue where my dev site I was building stopped connecting to the DB, and just as the OP it was saying:
希望这会帮助别人。我突然遇到了一个问题,我正在构建的开发站点停止连接到数据库,正如 OP 所说:
PDOException SQLSTATE[HY000] [1049] Unknown database 'forge' failed
After much head scratching (!) I found that my hostname value set inside the /bootstrap/start.php was wrong, because my hostname had changed on my macbook pro!? I have no idea how but it changed from something like RobMacbookPro2.local
to RobMacbookPro.local
. This meant it fell back to production thus loading the incorrect database.php file with the standard DB=forge (which was wrong)
经过多次摸索(!),我发现我在 /bootstrap/start.php 中设置的主机名值是错误的,因为我的主机名在我的 macbook pro 上发生了变化!?我不知道如何,但它像变RobMacbookPro2.local
到RobMacbookPro.local
。这意味着它退回到生产中,从而使用标准 DB=forge 加载了不正确的 database.php 文件(这是错误的)
Check this guide: http://laravel.com/docs/4.2/configuration
检查本指南:http: //laravel.com/docs/4.2/configuration
Pay particular attention to the code:
特别注意代码:
<?php
$env = $app->detectEnvironment(array(
'local' => array('your-machine-name'),
));
On a mac and probably linux? you can determine your hostname by typing # hostname
in terminal.
在 mac 上,可能在 linux 上?您可以通过# hostname
在终端中输入来确定您的主机名。
Hope that saves someone some time!
希望能节省一些时间!
回答by akshay ahir
If you are running both Xampp and MySQL Workbench, or if You are Running Xampp on the port other than the default port, there may be chances of confusion, you may have created the database using PHPMyAdmin and you are trying to connect it to localhost:cusotmport(e.g. localhost:8080). what I suggest is to create the database you want using MySQL workbench and then you would get your task done...
如果您同时运行 Xampp 和 MySQL Workbench,或者如果您在默认端口以外的端口上运行 Xampp,则可能会出现混淆,您可能已经使用 PHPMyAdmin 创建了数据库,并且正在尝试将其连接到本地主机:cusotmport(例如本地主机:8080)。我的建议是使用 MySQL Workbench 创建你想要的数据库,然后你就可以完成你的任务......