laravel连接mysql,如何使用laravel连接到mysql?

This is such a simple basic question I don't think there is much people asking this but simply how do I connect to mySql through localhost phpmyadmin with laravel (I've searched, there is some stuff, but I need to ask because I am a noob and I'd like to ask, the stuff I saw I don't quite get 100% or I tried and it didn't help)?

I am working with backbone.js and am brand new to laravel, I installed laravel inside C:\wamp\www\laravel-project

I tried

c:\wamp\www\laravel-project> php artisan migrate:make create_tasks_table --table tasks --create

And

c:\wamp\www\laravel-project> php artisan migrate

I expect to have to define the database information, I checked C:\wamp\www\laravel-project\app\config\database.php and it looks correct, mySQL is set on the defaults root being the user name, and '' empty being the password.

The error in the command line I get after running php artisan migrate is

[PDOException]

SQLSTATE[HY000] [1049] Unknown database 'database'

I am using windows 8, and wamp for my localhost server, it of course includes phpmyadmin and mySql. So I am sure there are tons of ways to use mySql but I don't think I am setting up laravel and phpmyadmin properly.

So any insight would be amazing, easy points.

EDIT:

Actually thinking this through maybe I need to create a database named database let me try that. be back soon. Okay I'll answer my question or someone can, just in case someone searches this topic... it is KEY to make sure the database defined in C:\wamp\www\laravel-project\app\config\database.php matches a database that exists inside your phpmyadmin. No brainer!

解决方案

Laravel makes it very easy to manage your database connections through app/config/database.php.

As you noted, it is looking for a database called 'database'. The reason being that this is the default name in the database configuration file.

'mysql' => array(

'driver' => 'mysql',

'host' => 'localhost',

'database' => 'database',

'username' => 'root',

'password' => '',

'charset' => 'utf8',

'collation' => 'utf8_unicode_ci',

'prefix' => '',

),

Change this to the name of the database that you would like to connect to like this:

'mysql' => array(

'driver' => 'mysql',

'host' => 'localhost',

'database' => 'my_awesome_data',

'username' => 'root',

'password' => '',

'charset' => 'utf8',

'collation' => 'utf8_unicode_ci',

'prefix' => '',

),

Once you have this configured correctly you will easily be able to access your database!

Happy Coding!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值