Php Artisan迁移访问被拒绝
我在建立一个拉威尔环境。因此,我下载了XAMPP并相应地配置了vhost文件。然后,我设置MySQL并运行以下命令:Php Artisan迁移访问被拒绝,php,mysql,laravel,xampp,artisan-migrate,Php,Mysql,Laravel,Xampp,Artisan Migrate,我在建立一个拉威尔环境。因此,我下载了XAMPP并相应地配置了vhost文件。然后,我设置MySQL并运行以下命令: 编写器安装 npm安装 php artisan(确认我有artisan) php artisan迁移 运行数字4之后,我在图片中得到以下错误 C:\Users\Aslam\Desktop\Pfera_application\pfera-web>php artisan migrate -v Illuminate\Database\QueryException : S
C:\Users\Aslam\Desktop\Pfera_application\pfera-web>php artisan migrate -v
Illuminate\Database\QueryException : SQLSTATE[HY000] [1045] Access denied for user 'forge'@'localhost' (using password: YES) (SQL: select * from information_schema.tables where table_schema = forge and table_name = migrations)
at C:\Users\Aslam\Desktop\Pfera_application\pfera-web\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:
669: return $result;
Exception trace:
1 Doctrine\DBAL\Driver\PDOException::("SQLSTATE[HY000] [1045] Access denied for user 'forge'@'localhost' (using password: YES)")
C:\Users\Aslam\Desktop\Pfera_application\pfera-web\vendor\doctrine\dbal\lib\Doctrine\DBAL\Driver\PDOConnection.php : 50
请帮忙!!!非常感谢
PS,下面是database.php文件:
<?php
return [
/*
|--------------------------------------------------------------------------
| Default Database Connection Name
|--------------------------------------------------------------------------
|
| Here you may specify which of the database connections below you wish
| to use as your default connection for all database work. Of course
| you may use many connections at once using the Database library.
|
*/
'default' => env('DB_CONNECTION', 'mysql'),
/*
|--------------------------------------------------------------------------
| Database Connections
|--------------------------------------------------------------------------
|
| Here are each of the database connections setup for your application.
| Of course, examples of configuring each database platform that is
| supported by Laravel is shown below to make development simple.
|
|
| All database work in Laravel is done through the PHP PDO facilities
| so make sure you have the driver for your particular database of
| choice installed on your machine before you begin development.
|
*/
'connections' => [
'sqlite' => [
'driver' => 'sqlite',
'database' => env('DB_DATABASE', database_path('database.sqlite')),
'prefix' => '',
],
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'strict' => true,
'engine' => null,
],
'pgsql' => [
'driver' => 'pgsql',
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '5432'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'prefix' => '',
'schema' => 'public',
'sslmode' => 'prefer',
],
'sqlsrv' => [
'driver' => 'sqlsrv',
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', '1433'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'prefix' => '',
],
],
/*
|--------------------------------------------------------------------------
| Migration Repository Table
|--------------------------------------------------------------------------
|
| This table keeps track of all the migrations that have already run for
| your application. Using this information, we can determine which of
| the migrations on disk haven't actually been run in the database.
|
*/
'migrations' => 'migrations',
/*
|--------------------------------------------------------------------------
| Redis Databases
|--------------------------------------------------------------------------
|
| Redis is an open source, fast, and advanced key-value store that also
| provides a richer set of commands than a typical key-value systems
| such as APC or Memcached. Laravel makes it easy to dig right in.
|
*/
'redis' => [
'client' => 'predis',
'default' => [
'host' => env('REDIS_HOST', '127.0.0.1'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', 6379),
'database' => 0,
],
],
];
Laravel仍在尝试使用默认的Forge配置。您需要打开
.env
和config/database.php
文件,并为MySQL配置连接信息
您的config/database.php
文件很可能已经为MySQL配置好了,所以我将主要介绍您的.env
文件。.env
文件存在,因此您可以为开发和生产环境定义不同的选项
在.env
文件中,按如下方式进行配置:
DB_CONNECTION=mysql
DB_TEST_DATABASE=database_name
DB_TEST_USERNAME=mysql_user_with_access_to_the_database
DB_TEST_PASSWORD=your_super_secure_password
默认情况下,
config/database.php
文件设置为从.env
文件中提取此信息。如果.env
文件不存在,则它有自己的回退信息。您与数据库的laravel.env
的错误相关配置
数据库=宅地
DB_USERNAME=宅地
DB_PASSWORD=secret
数据库连接数据在config/database.php文件中定义,mysql行如下:
'host' => env('DB_HOST', 'localhost'),
其中第一个参数表示从.env文件获取此值,如果无法加载该信息,则出于任何原因,请使用第二个参数。
因此,您应该在这两个文件中定义凭据
如果没有任何帮助,请使用
'host' => 'localhost',
与数据库配置行的每一行相对应如果您确定数据库用户和密码,然后尝试在cli中退出artisan服务器并重新运行,则这是一个连接错误
php artisan serve
如果你不确定你的用户名或密码,你正在与流浪者一起使用宅地
试试下面的方法
DB_DATABASE=forge
DB_USERNAME=homestead
DB_PASSWORD=secret
如果你不确定你的密码和用户名,并且没有使用流浪者家园
试试这个
DB_DATABASE=forge
DB_USERNAME=root
DB_PASSWORD=
我的.env就是这样设置的。请附上你的database.php文件。env文件是seup正确的。我已经检查了DB_database=homestead DB_USERNAME=homestead DB_PASSWORD=secretI再次编辑了这篇文章,包括php数据库文件和.env文件。你正在连接mysql吗@珍妮:是的,这就是我想做的。但不幸的是出现了错误…创建新数据库并将其与laravel连接,然后发出命令:
php artisan migrate
@jennyyu唯一更改的是“SQLSTATE[HY000][2054]服务器请求的身份验证方法客户端不知道(SQL:从信息_schema.tables中选择*,其中table_schema=forge和table_name=migrations)
DB_DATABASE=forge
DB_USERNAME=root
DB_PASSWORD=