我尝试跑步:
php artisan migrate
还可以在 Windows 上使用 Xampp 连接到 MySQL。
我收到此错误:
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 文件:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=
打开
.env
文件并进行编辑。只需设置正确的数据库凭据:
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
如果您在xampp
中安装MySQL时没有默认的用户名,则应将
DB_USERNAME
设置为root
。
如果数据库没有设置密码,清除它
DB_PASSWORD
,空格也必须去掉(以前我也遇到过这个问题,window把空格当密码)
完成
.env
编辑后,请在终端中输入此命令以清除缓存:
php artisan config:cache
对于使用 MAMP 的 Mac 用户,如果接受的答案不足以解决此问题,就像我一样,请将
socket
添加到 .env
文件中。
DB_SOCKET=/Applications/MAMP/tmp/mysql/mysql.sock
//or
UNIX_SOCKET=/Applications/MAMP/tmp/mysql/mysql.sock
该变量应与
config > database.php
上的设置匹配。寻找connections > mysql > unix_socket
您好,请转到 xampp phpmyadmin 创建一个数据库作为示例堆栈并将您的 .env 更改为:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=stack
DB_USERNAME=root
DB_PASSWORD=
默认 phpmyadmin 用户名是 root 并且没有密码 保存并尝试
php artisan migrate
你应该尝试这个:
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`)
然后运行以下命令
php artisan config:cache
php artisan cache:clear
php artisan migrate
我遇到了同样的错误,直到我更改了
DB_PORT
并设置了 MAMP 中的值
尝试一下,转到您的
.env
文件,更改数据库的名称。
转到 phpmyadmin,在 .env
文件中使用新名称创建一个新数据库。
然后运行
php artisan migrate
确保您的 .env 文件正确
转到 mysql/data/database_name /tablename.ibd 文件并手动删除它。之后尝试你的命令 php artisan migrate
对于 Windows 例如 C:\xampp\mysql\data ogDBablename.ibd<======
php artisan config:cache
php artisan migrate
php artisan serve
在您的终端中尝试以下操作:启动 XMAPP 使用
sudo /opt/lampp/lampp start
控制台输出应该是
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.
当您收到错误时
error: /opt/lampp/bin/mysql.server: 264: kill: No such process**
在您的终端中重试此操作:
sudo service mysql stop
sudo service apache2 stop
迁移文件后打开数据库。
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
我正在使用 MacOS 和 MAMP
我尝试了上述建议,但无法解决。
为我解决的问题是在 MAMP 中从 PHP 7.x 切换到 8.0.x。