Laravel [1045] Access denied for user 'homestead'@'localhost' .env没有配置
laravel 连接数据库出现错误
PDOException in Connector.php line 55:SQLSTATE[HY000] [1045]
Access denied for user 'homestead'@'localhost' (using password: YES)
1. 确认./config/database.php
<?php
return [
'default' => env('DB_CONNECTION', 'mysql'),
'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', 'studyonline'),
'username' => env('DB_USERNAME', 'root'),
'password' => env('DB_PASSWORD', ''),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8',
'collation' => 'utf8_general_ci',
'prefix' => '',
'strict' => true,
'engine' => null,
],
// ...
]
]
2. 检查.env文件
默认的配置导致的错误
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret
APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:cdQLOKNt6JfRuIwfABQ/rqDuR42lgFi8qCC5b4R/KsI=
APP_DEBUG=true
APP_URL=http://localhost LOG_CHANNEL=stack DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=studyonline
DB_USERNAME=root
DB_PASSWORD=
3. 重启服务
php artisan cache:clear
php artisan config:clear
php artisan serve
cd ./public
php -S localhost:9000
laravel artisan 一些命令
* 创建model
php artisan make:model Video
执行后生成 ./app/Video.php
<?php namespace App; use Illuminate\Database\Eloquent\Model; class Video extends Model
{
//
}
* 创建Controller
php artisan make:controller UserController
执行后生成 ./app/Http/Controllers/UserController.php
<?php
namespace App\Http\Controllers; use Illuminate\Http\Request; class UserController extends Controller { }
* 创建数据库消息队列的数据表迁移文件
php artisan queue:table
=> database/migrations/2018_07_21_033228_create_jobs_table.php
<?php use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration; class CreateJobsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('jobs', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('queue')->index();
$table->longText('payload');
$table->unsignedTinyInteger('attempts');
$table->unsignedInteger('reserved_at')->nullable();
$table->unsignedInteger('available_at');
$table->unsignedInteger('created_at');
});
} /**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('jobs');
}
}
迁移文件
php artisan migrate
=> 数据表结构 jobs表
-- MySQL dump 10.16 Distrib 10.1.31-MariaDB, for osx10.6 (i386)
--
-- Host: localhost Database: laravel
-- ------------------------------------------------------
-- Server version 10.1.31-MariaDB /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; --
-- Table structure for table `jobs`
-- DROP TABLE IF EXISTS `jobs`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `jobs` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`queue` varchar(255) NOT NULL,
`payload` longtext NOT NULL,
`attempts` tinyint(3) unsigned NOT NULL,
`reserved_at` int(10) unsigned DEFAULT NULL,
`available_at` int(10) unsigned NOT NULL,
`created_at` int(10) unsigned NOT NULL,
PRIMARY KEY (`id`),
KEY `jobs_queue_index` (`queue`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */; --
-- Dumping data for table `jobs`
-- LOCK TABLES `jobs` WRITE;
/*!40000 ALTER TABLE `jobs` DISABLE KEYS */;
/*!40000 ALTER TABLE `jobs` ENABLE KEYS */;
UNLOCK TABLES;
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; /*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; -- Dump completed on 2018-07-21 11:39:29
jobs.sql
假设数据库名为 laravel, 导出这个表
mysqldump -uroot -hlocalhost -p --databases laravel --tables jobs > jobs.sql
创建controller
php artisan make:controller WelcomeController
ERROR:
Illuminate \ Database \ QueryException(42S22)
Timestamps
By default, Eloquent expects created_at
and updated_at
columns to exist on your tables. If you do not wish to have these columns automatically managed by Eloquent, set the $timestamps
property on your model to false
:
<?php namespace App; use Illuminate\Database\Eloquent\Model; class Video extends Model {
protected $table = 't_video';
protected $primaryKey = 'id';
public $timestamps = false; /* Indicates if the model should be timestamped. */
}
Laravel [1045] Access denied for user 'homestead'@'localhost' .env没有配置的更多相关文章
- Laravel [1045] 解决方法 Access denied for user 'homestead'@'localhost'
这几天学习Laravel框架遇到了数据库方面的问题. PDOException in Connector.php line 55:SQLSTATE[HY000] [1045] Access denie ...
- phpmyadmin #1045 - Access denied for user 'root'@'localhost' (using password: NO)
phpmyadmin访问遇到1045问题 #1045 - Access denied for user 'root'@'localhost' (using password: NO) 解决办法 找到p ...
- Windows mysql提示:1045 access denied for user 'root'@'localhost' using password yes
Windows mysql提示:1045 access denied for user 'root'@'localhost' using password yes http://blog.csdn.n ...
- 1045 access denied for user 'root'@'localhost' using password yes的解决方法
今天把一个项目和项目的数据库都下载到了本地,安装好项目和在本地配置好数据库后,在浏览器登陆项目的后台却出现了以下错误: 后来上百度搜索了好几个答案,都是讲述修改数据库密码的步骤,但是就是没有说明为 ...
- windows mysql提示:1045 access denied for user 'root'@'localhost' using password yes 解决方案
win7 MySql5.6.17提示:1045 access denied for user 'root'@'localhost' using password yes 从网上找到的解决方法,以此博客 ...
- wamp中的phpmyadmin打开出现:#1045 - Access denied for user 'root'@'localhost' (using password: NO)
详细内容: MySQL said: #1045 - Access denied for user 'root'@'localhost' (using password: NO) phpMyAdmin ...
- ERROR 1045: Access denied for user: 'root@localhost' (Using password: YES)(转)
前两天也偶尔出现这个错误,也没在意,因为我重新修改一下mysql的root密码后又可以用了,但昨天却不行,我把root密码修改以后虽然当时能用, 一旦重新进入就都不能用了,可我的密码明明没有错啊?今天 ...
- CDbConnection failed to open the DB connection: SQLSTATE[28000] [1045] Access denied for user 'root'@'localhost' (using password: YES)
连接mysql出错:CDbConnection failed to open the DB connection: SQLSTATE[28000] [1045] Access denied for u ...
- 错误代码1045 Access denied for user 'root'@'localhost' (using password:YES)
在mysql中新建连接,ip地址是127.0.0.1,账号是root,密码是123456,但是测试连接的时候报错, 错误代码1045 Access denied for user 'root'@'lo ...
随机推荐
- GIT-版本管理-初阶使用
目前我用的比较多的git指令 git clone -b [branch-name]: 拉取远程指定分支代码 git status: 查看工作区修改状态 在将修改添加进暂存区的时候需要git add . ...
- luogu P6239 奇怪的道路
奇怪的道路 我看不出来是状压的状压 好吧,其实看到k的范围应该去往状压方面想的. 然后,题目中说"任何一个城市都与恰好偶数条道路相连(0也被认为是偶数)". 所以,奇偶,两种状态可 ...
- NOIP 模拟 $30\; \rm 毛三琛$
题解 \(by\;zj\varphi\) 二分答案,考虑二分背包中的最大值是多少. 枚举 \(p\) 的值,在当前最优答案不优时,直接跳掉. 随机化一下 \(p\),这样复杂度会有保证. Code # ...
- 题解 数列 及exgcd总结
传送门 自闭了--考场上exgcd打错然后对着屏幕自闭了一个小时不知道它为什么解得不对 开始恶补: 对于方程 \(a*x+b*y=c\) ,就等价于 \(a*x \equiv c\pmod{b}\) ...
- 题解 Connect
传送门 各种骗分无果,特殊性质还手残写挂了-- 首先完全图上直接输出边权 \(\times (n-2)\) 就行了,然而我脑残乘的 \(n-1\) 看数据范围肯定是状压,但是压边肯定炸了,考虑压点 因 ...
- 【设计模式】装饰者模式(DecoratorMode0
From: https://liudongdong1.github.io/ 装饰者模式(Decorator Pattern):动态地给一个对象增加一些额外的职责,增加对象功能来说,装饰模式比生成子类实 ...
- C++ 计算MD5
头文件: #pragma once #ifndef MD5_H #define MD5_H #include <string> #include <fstream> /* Ty ...
- Spring详解(十)------spring 环境切换
软件开发过程一般涉及"开发 -> 测试 -> 部署上线"多个阶段,每个阶段的环境的配置参数会有不同,如数据源,文件路径等.为避免每次切换环境时都要进行参数配置等繁琐的操 ...
- Spring第一课:依赖注入DI(二)
DI Dependency Injection ,依赖注入 is a :是一个,继承. has a:有一个,成员变量,依赖. class B { private A a; //B类依赖A类 } 依 ...
- JDBC基础篇(MYSQL)——PreparedStatement执行DML、DQL等
注意:其中的JdbcUtil是我自定义的连接工具类:代码例子链接: package day03.prepare; import java.sql.Connection; import java.sql ...