To connect to the MySQL database in Laravel, you need to provide the configuration information in the Laravel project's .env
file. Here are detailed instructions:
-
Open the
.env
file: Open the.env
file in the root directory of your Laravel project. -
Configure the MySQL connection: Locate the following configuration lines and update them to match your MySQL connection information:
DB_CONNECTION=mysql DB_HOST=your_mysql_host DB_PORT=your_mysql_port DB_DATABASE=your_mysql_database DB_USERNAME=your_mysql_username DB_PASSWORD=your_mysql_password
-
Save the
.env
file: Once you have updated the connection details, save the.env
file.
After completing these steps, Laravel will use your MySQL connection configuration to connect and interact with the database. You can use SQL queries or leverage Laravel's ORM (Eloquent)
to work with MySQL data in your application.