Skip to content
Advertisement

Why password argument read as username in exec()

I tried to seed using sql file using exec() function in Laravel Seeder, shown below:

exec("mysql -u ". env('DB_USERNAME') ." -p". env('DB_PASSWORD') ." ". env('DB_DATABASE') ." < " . database_path() . '/seeds/table.sql');

But when executed php artisan db:seed --class MySeeder, I got this output

ERROR 1045 (28000): Access denied for user '-p'@'localhost' (using password: NO)

It was always like that, no matter password argument I used (-p and --password).

But in other side, using windows with this line of code below, it works well.

exec("C:/xampp/mysql/bin/mysql -u " . env('DB_USERNAME') . " --password=" . env('DB_PASSWORD') . " " . env('DB_DATABASE') . " < " . database_path() . '/seeds/table.sql');

The reason I did this is because the mysql file is huge, I cannot convert or type it manual to proper seeder each rows. Can someone help me? Should I use different methods? Thank you

Details:

  • Ubuntu subsystem on Windows 10
  • Ubuntu 18.04 on DigitalOcean
  • Laravel 7
  • PHP 7.3
  • MySQL (php7.3-mysql + mysql_server)

Advertisement

Answer

I’m so dumb, I found my solution by accident. I executed:

composer dumpautoload

php artisan config:clear

php artisan cache:clear

But I guess composer dumpautoload was the answer. And I don’t know why. If someone have perfect reason why composer dumpautoload solved my problem, feel free to comment 🙂

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement