dpb42021 2015-05-14 13:53
浏览 101
已采纳

Laravel / MySQL数据库连接

I have an unusual problem with my Laravel 4.2 project connecting to MySQL database. This is my 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.

First, I've created a database in phpMyAdmin. When I tried to run php artisan migrate, it gave me an error of unknown database 'database_name'. I thought it was silly since I've just created a database in 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. It seems to me that the Laravel project is connected to a different mysql server than the phpMyAdmin. 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.

  • 写回答

1条回答 默认 最新

  • drsb77336 2015-05-21 09:33
    关注

    I solved the problem by following the solution in the link provided by Bulk. I just have to run sudo /opt/lampp/bin/php artisan migrate instead of the plain php artisan migrate. With this, artisan will use the MySQL version provided by XAMPP.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?