简体   繁体   English

如何修复“Illuminate\\Database\\QueryException: SQLSTATE[HY000] [1044] Access denied for user”

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

I tried to run: php artisan migrate我试着运行: php artisan migrate

Also to connect to MySQL using Xampp on Windows.还可以在 Windows 上使用 Xampp 连接到 MySQL。

I Got this error:我收到这个错误:

Illuminate\Database\QueryException  : 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:\Users\harsh\Laravel1\vendor\laravel\framework\src\Illuminate\Database\Connection.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:\Users\harsh\Laravel1\vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.php:70

  2  
PDO::__construct("mysql:host=127.0.0.1;port=3306;dbname=homestead",
"homestead", "", [])
      C:\Users\harsh\Laravel1\vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.php:70

  Please use the argument -v to see more details.

.env file: .env 文件:

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

Open the .env file and edit it.打开.env文件并进行编辑。 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 .如果您在xampp 中安装 MySQL 时没有默认用户名,则应将DB_USERNAME设置为root

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)如果数据库没有设置密码,清除它DB_PASSWORD空格也必须删除(过去我也遇到过这个问题,窗口将空格视为密码)

After completion of .env edit please enter this command in your terminal for clear cache:完成.env编辑后,请在终端中输入此命令以清除缓存:

php artisan config:cache

Hi go to xampp phpmyadmin create a database for exemple stack and change your .env to this:嗨,去 xampp phpmyadmin 为示例堆栈创建一个数据库,并将您的 .env 更改为:

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默认情况下 phpmyadmin 用户名是 root 并且没有密码保存并尝试php artisan migrate

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

Try this, go to your .env file, change the name of the database.试试这个,转到您的.env文件,更改数据库的名称。 Go to your phpmyadmin, create a new database with the new name in your .env file.转到您的 phpmyadmin,在.env文件中使用新名称创建一个新数据库。

Then run php artisan migrate然后运行php artisan migrate

在更改DB_PORT并从 MAMP 设置值之前,我一直DB_PORT相同的错误

For Mac users using MAMP, if the accepted answer was not enough to solve this issue, like me, add socket to the .env file.对于使用 MAMP 的 Mac 用户,如果接受的答案不足以解决这个问题,就像我一样,将socket添加到.env文件中。

DB_SOCKET=/Applications/MAMP/tmp/mysql/mysql.sock
//or
UNIX_SOCKET=/Applications/MAMP/tmp/mysql/mysql.sock

The variable should match with the setting on config > database.php .该变量应与config > database.php上的设置匹配。 Look for connections > mysql > unix_socket查找connections > mysql > unix_socket

Try this in your terminal: To start XMAPP use在你的终端中试试这个:启动 XMAPP 使用

sudo /opt/lampp/lampp start

Console output should be控制台输出应该是

Starting XAMPP for Linux 7.4.8-0...
XAMPP: Starting Apache...fail.
XAMPP: Another web server is already running.
XAMPP: Starting MySQL...ok.
XAMPP: Starting ProFTPD...ok.

When you get the error当你得到错误

error: /opt/lampp/bin/mysql.server: 264: kill: No such process**

try this again in your terminal:在您的终端中再试一次:

sudo service mysql stop
sudo service apache2 stop

Then open datatbase after migrating the file.然后在迁移文件后打开数据库。

you fix file .env Pay attention to the password section 'password'
 +need to have '
 
 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 
 

I'm using MacOS and MAMP我正在使用 MacOS 和 MAMP

I tried the above mentioned suggestions but I couldn't solve it.我尝试了上述建议,但无法解决。

What solved it for me was switching from PHP 7.x to 8.0.x in MAMP .为我解决的是在 MAMP 中从 PHP 7.x 切换到 8.0.x

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Illuminate\Database\QueryException: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (使用密码: YES) - Illuminate\Database\QueryException : SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) SQLSTATE [HY000] [1044] cPanel中的用户访问被拒绝 - SQLSTATE[HY000] [1044] Access denied for user in cPanel SQLSTATE [HY000] [1044]当用户'@'localhost'上传到PhpMyAdmin数据库表时,访问被拒绝 - SQLSTATE[HY000] [1044] Access denied for user ''@'localhost' when uploading to PhpMyAdmin database table pdoexception sqlstate hy000 1044用户'@'localhost'对数据库'laravel'的访问被拒绝 - pdoexception sqlstate hy000 1044 access denied for user ''@'localhost' to database 'laravel' Illuminate\Database\QueryException: SQLSTATE[HY000] [2002] 在文件 Illuminate/Database/Connection.php 上的第 678 行 - Illuminate\Database\QueryException: SQLSTATE[HY000] [2002] in file Illuminate/Database/Connection.php on line 678 警告: mysqli::mysqli(): (HY000/1044): 用户访问被拒绝 - Warning: mysqli::mysqli(): (HY000/1044): Access denied for user SQLSTATE [HY000] [1045] 用户'root'@'localhost'在../laravel/framework/src/Illuminate/Database/Connectors/Connector.php:70 的访问被拒绝 - SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' at ../laravel/framework/src/Illuminate/Database/Connectors/Connector.php:70 我在cPanel上传了一个laravel项目,我收到此错误:SQLSTATE [HY000] [1044]用户拒绝访问 - I uploaded a laravel project in cPanel and I'm getting this error: SQLSTATE[HY000] [1044] Access denied for user Laravel 6-MariaDB 10.1:Illuminate \\ Database \\ QueryException:SQLSTATE [HY000]迁移错误 - Laravel 6 - MariaDB 10.1: Illuminate\Database\QueryException : SQLSTATE[HY000] migration error Illuminate \\ Database \\ QueryException (2002) SQLSTATE[HY000] [2002] 没有这样的文件或目录 (SQL: select * from `rents`) - Illuminate \ Database \ QueryException (2002) SQLSTATE[HY000] [2002] No such file or directory (SQL: select * from `rents`)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM