1
votes

I am trying to make CRUD operations in laravel and I alway have this error message. I already configured the .env and the config/database.php files to my local setting but it doesn't work.

I tried php artisan cache:clear,php artisan config:clear too...

My config/database.php:

'mysql' => [
    'driver' => 'mysql',
    'host' => env('DB_HOST', 'localhost'),
    'port' => env('DB_PORT', ''),
    'database' => env('DB_DATABASE', 'feki_test'),
    'username' => env('DB_USERNAME', 'root'),
    'password' => env('DB_PASSWORD', ''),
    'unix_socket' => env('DB_SOCKET', ''),
    'charset' => 'utf8mb4',
    'collation' => 'utf8mb4_unicode_ci',
    'prefix' => '',
    'strict' => true,
    'engine' => null,
],

My .env:

DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=
DB_DATABASE=feki_test
DB_USERNAME=root
DB_PASSWORD=
5
Are you sure that you can login to your local MySQL with those credentials? It seems like your MySQL server have a password for the root user. Try to connect to MySQL from the command line with the same credentials. - BDS
Try to manually verify the credentials once. And any reason that you're not defining the port and even clearing the default value? - Sandeesh
I navigated in the windows command prompt to C:\xampp\mysql\bin and used the "mysql -u root -p" command which worked after I left the password blank - user5765320
Yes, I am using phpmyadmin in XAMPP, where the user is "root" and there is no password. The host is localhost, that's why I modified the files. It's working with raw laravel setup, but not with homestead.. - user5765320
@AlexitsPatrik homestead use a vm , so ur XAMPP serve is in-effective in that case, check the homestead docs for the default user & pass. - ctf0

5 Answers

3
votes

I was facing the same issue. But I found the solution by deleting the config.php file saved in the bootstrap/cache/config.php. After that simply run these commands

php artisan config:clear
php artisan cache:clear
php artisan config:cache
1
votes

Based on the comments, you're trying to access the local xampp mysql server from within Homestead. This won't work as the application is in an isolated virtual machine. You will need to use Homestead's mysql server for your application. Use the default connection information for this.

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret

To access Homestead's server on your local machine change the port to 33060. This can be helpful if you want to use a SQL tool to connect to the database.

0
votes

First of all, you need not write credentials in config/database.php. then delete you .env file and then rename your .env.example file to .env afterward run the PHP artisan key:generate command on your terminal .

give your database credential.

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=feki_test
DB_USERNAME=root
DB_PASSWORD=

and the last restart your development server. .

0
votes

In .env and config->database.php file

Instead of this

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=feki_test
DB_USERNAME=root
DB_PASSWORD=

Use this

DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=db_name
DB_USERNAME=root
DB_PASSWORD=''

and then restart your server. It will work for sure

0
votes

i changed 127.0.0.1 to localhost And its worked

DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=efaf
DB_USERNAME=root
DB_PASSWORD=