How to fix “Illuminate\Database\QueryException: SQLSTATE[HY000] [1044] Access denied for user”

问题: I tried to run: php artisan migrate Also to connect to MySQL using Xampp on Windows. I Got this error: IlluminateDatabaseQueryException : SQLSTATE[HY000] [1044]...

问题:

I tried to run: php artisan migrate

Also to connect to MySQL using Xampp on Windows.

I Got this error:

IlluminateDatabaseQueryException : SQLSTATE[HY000] [1044] Access denied for user ''@'localhost' to database 'homestead' (SQL: select * from information_schema.tables where table_schema = homestead and table_name = migrations)

at C:UsersharshLaravel1vendorlaravelframeworksrcIlluminateDatabaseConnection.php:664 660| // If an exception occurs when attempting to run a query, we'll format the error 661| // message to include the bindings with SQL, which will make this exception a 662| // lot more helpful to the developer instead of just the database's errors. 663| catch (Exception $e) {

664| throw new QueryException( 665| $query, $this->prepareBindings($bindings), $e 666| ); 667| } 668| Exception trace:

1 PDOException::("SQLSTATE[HY000] [1044] Access denied for user ''@'localhost' to database 'homestead'") C:UsersharshLaravel1vendorlaravelframeworksrcIlluminateDatabaseConnectorsConnector.php:70

2
PDO::__construct("mysql:host=127.0.0.1;port=3306;dbname=homestead", "homestead", "", []) C:UsersharshLaravel1vendorlaravelframeworksrcIlluminateDatabaseConnectorsConnector.php:70

Please use the argument -v to see more details.

.env file:

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

回答1:

Open the .env file and edit it. Just set up correct DB credentials:

DB_CONNECTION=mysql 
DB_HOST=127.0.0.1 
DB_PORT=3306 
DB_DATABASE=            // Your Database Name
DB_USERNAME=           // Yout Database Username
DB_PASSWORD=          // Your Database Password 

The DB_USERNAME should be set to root if you do not have a default username in the installation of MySQL in xampp.

If no password is set on the database, clear it DB_PASSWORD, empty space must also be removed(In the past I've also faceout this problem, window consider blank space as a password)

After completion of .env edit please enter this command in your terminal for clear cache:

php artisan config:cache

回答2:

Hi go to xampp phpmyadmin create a database for exemple stack and change your .env to this:

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

by default phpmyadmin username is root and without password save and try php artisan migrate


回答3:

You should try this:

DB_CONNECTION=mysql 
DB_HOST=127.0.0.1 
DB_PORT=3306 
DB_DATABASE=your database name 
DB_USERNAME= your localhost-database username (i.e `root`)
DB_PASSWORD= your localhost-database password (i.e `root`)

then you run below command

php artisan config:cache
php artisan cache:clear 
php artisan migrate
  • 发表于 2019-01-15 04:58
  • 阅读 ( 1038 )
  • 分类:网络文章

条评论

请先 登录 后评论
不写代码的码农
小编

篇文章

作家榜 »

  1. 小编 文章
返回顶部
部分文章转自于网络,若有侵权请联系我们删除