Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't Figure out how to set up a database on Laravel

This is becoming a really annoying problem. I am following the Quick setup directions on laravel.com. I have followed all the steps until I have to go:

php artisan migrate

The result is:

[PDOException]
  SQLSTATE[42000] [1049] Unknown database 'database'



migrate [--bench[="..."]] [--database[="..."]] [--path[="..."]] [--package[="..."]] [--pretend] [--seed]

And I go back and check the database.php file and it reads:

'mysql' => array(
    'driver'    => 'mysql',
    'host'      => 'localhost',
    'database'  => 'database',
    'username'  => 'root',
    'password'  => '',
    'charset'   => 'utf8',
    'collation' => 'utf8_unicode_ci',
    'prefix'    => '',
),

Afterwards, I go to localhost:8000/users and it displays:

    PDOException
    SQLSTATE[42000] [1049] Unknown database 'database'
    open: /Users/benamorgan/Sites/run-away-world/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php
         */


    public function createConnection($dsn, array $config, array $options)
        {
            $username = array_get($config, 'username');

            $password = array_get($config, 'password');

            return new PDO($dsn, $username, $password, $options);
        }

I have been trying to change the database name, provide a root password, start and stop mysql, change the naming in every possible way for database, change localhost to 127.0.0.1. I don't know what to do, hence I'm stopping by here to ask where I messed up.

like image 804
Ben Morgan Avatar asked Dec 19 '22 21:12

Ben Morgan


1 Answers

Laravel doesn't create databases for you, you need to do it on your own. Log in to mysql and create your database, then provide the name in your db config.

You can do it quickly in your console:

echo "create database my_database" | mysql -u root -p

then in your config change the database name:

'database'  => 'my_database',
like image 119
mariodev Avatar answered Dec 24 '22 03:12

mariodev