Lraravel supports MySQL, PostgreSQL, SQL Server and SQLite database. Database setup is stored in .env
file and config/database.php
.
The priority of database setup information is:
.env
> config/database.php
Setup procedure for database connection:
SQLite:
- Add a empty sqlite database file.
> touch database/database.sqlite
- Comment out:
#DB_CONNECTION=mysql
#DB_HOST=127.0.0.1
#DB_PORT=3306
#DB_DATABASE=homestead
#DB_USERNAME=homestead
#DB_PASSWORD=secret
- Add commends to
.env
file:
DB_CONNECTION=sqlite
DB_DATABASE=database/database.sqlite
php artisan migrate
MySQL:
- Add a new database in mysql server.
- Edit .env file:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=xxxxx
DB_USERNAME=xxxxx
DB_PASSWORD=xxxx
php artisan migrate
Migration table created successfully.
Migrating: 2014_10_12_000000_create_users_table
Migrated: 2014_10_12_000000_create_users_table
Migrating: 2014_10_12_100000_create_password_resets_table
Migrated: 2014_10_12_100000_create_password_resets_table
Using artisan command to create a database in mysql.
What if I want to create a database in Laravel?
Please refer to this article Using an Artisan command to create a database in Laravel or Lumen
No comments:
Post a Comment