[英]Laravel/MySQL database connection
I have an unusual problem with my Laravel 4.2 project connecting to MySQL database. 我的Laravel 4.2项目连接到MySQL数据库时遇到异常问题。 This is my database.php 这是我的database.php
'mysql' => array(
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'database_name',
'username' => 'root',
'password' => '',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
)
I use XAMPP for Ubuntu. 我将XAMPP用于Ubuntu。
First, I've created a database in phpMyAdmin. 首先,我在phpMyAdmin中创建了一个数据库。 When I tried to run php artisan migrate
, it gave me an error of unknown database 'database_name'
. 当我尝试运行php artisan migrate
,它给了我一个unknown database 'database_name'
的错误。 I thought it was silly since I've just created a database in phpMyAdmin. 我以为这很愚蠢,因为我刚刚在phpMyAdmin中创建了一个数据库。 Then I tried creating a database through the command line and tried running the migration again. 然后,我尝试通过命令行创建数据库,然后尝试再次运行迁移。 It worked. 有效。 Tables were created under the database I specified when I run show tables
in the command line. 在我在命令行中运行show tables
在我指定的数据库下创建了show tables
。 It seems to me that the Laravel project is connected to a different mysql server than the phpMyAdmin. 在我看来,Laravel项目连接到的是与phpMyAdmin不同的mysql服务器。 Is that even possible? 那有可能吗? How can I solve this problem? 我怎么解决这个问题?
I've been trying to solve this for hours but still, no luck. 我已经尝试解决了几个小时,但是仍然没有运气。 Hope someone can help me with my problem. 希望有人可以帮助我解决我的问题。
I solved the problem by following the solution in the link provided by Bulk. 我通过遵循Bulk提供的链接中的解决方案解决了该问题。 I just have to run sudo /opt/lampp/bin/php artisan migrate
instead of the plain php artisan migrate
. 我只需要运行sudo /opt/lampp/bin/php artisan migrate
而不是普通的php artisan migrate
sudo /opt/lampp/bin/php artisan migrate
。 With this, artisan
will use the MySQL version provided by XAMPP. 这样, artisan
将使用XAMPP提供的MySQL版本。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.