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)

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'updated_at' in 'field list' (SQL: update `t_video` set `location` = http://video.tfjyzx.com/cd16bf18f8394f2aa25fb1efc814a09e/e2ac5e5effd8490d819f6025b37c38c2-5287d2089db37e62345123a1be272f8b.mp4, `updated_at` = 2018-07-14 08:43:48 where `id` = 1)
 
@Ref: https://docs.golaravel.com/docs/5.6/eloquent/

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没有配置的更多相关文章

  1. Laravel [1045] 解决方法 Access denied for user 'homestead'@'localhost'

    这几天学习Laravel框架遇到了数据库方面的问题. PDOException in Connector.php line 55:SQLSTATE[HY000] [1045] Access denie ...

  2. phpmyadmin #1045 - Access denied for user 'root'@'localhost' (using password: NO)

    phpmyadmin访问遇到1045问题 #1045 - Access denied for user 'root'@'localhost' (using password: NO) 解决办法 找到p ...

  3. 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 ...

  4. 1045 access denied for user 'root'@'localhost' using password yes的解决方法

    今天把一个项目和项目的数据库都下载到了本地,安装好项目和在本地配置好数据库后,在浏览器登陆项目的后台却出现了以下错误:   后来上百度搜索了好几个答案,都是讲述修改数据库密码的步骤,但是就是没有说明为 ...

  5. 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 从网上找到的解决方法,以此博客 ...

  6. 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 ...

  7. ERROR 1045: Access denied for user: 'root@localhost' (Using password: YES)(转)

    前两天也偶尔出现这个错误,也没在意,因为我重新修改一下mysql的root密码后又可以用了,但昨天却不行,我把root密码修改以后虽然当时能用, 一旦重新进入就都不能用了,可我的密码明明没有错啊?今天 ...

  8. 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 ...

  9. 错误代码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 ...

随机推荐

  1. VMware 启动虚拟机黑屏(Ubuntu)

    之前启动都很正常,不知道为啥,最近启动,老出现这种黑屏得情况: 解决方法: 在搜索栏里搜索cmd 巴拉了一下谷歌,发现了问题: 虚拟机和主机之间的通信,基本上是以 socket 的方式进行通信的(这里 ...

  2. TortoiseGit冲突和解决冲突

    产生冲突原因 产生:多个开发者同时使用或者操作git中的同一个文件,最后在依次提交commit和推送push的时候,第一个操作的是可以正常提交的,而之后的开发者想要执行pull(拉)和pull(推)操 ...

  3. MFC 绘制坐标系

    主要讨论映射模式:MM_ANISOTROPIC,MM_ISOTROPIC.及相关方法的应用. 1,先建立一个MFC单文档,过程不再赘述. 2,在View类中找到CMainFrame::PreCreat ...

  4. WPF路由事件

    ​    这节讲一下WPF中的路由事件(Routed Event). [什么是事件] 在了解路由事件前,我们应先来了解一下什么是事件(Event). 在Windows系统中,像鼠标单击,双击,移动这样 ...

  5. final 关键字,你想知道的都在这里

    哈喽,大家好,我是指北君. 介绍完 native.static 关键字后,指北君马不停蹄,接着为大家介绍另一个常用的关键字--final. 对于Java中的 final 关键字,我们首先可以从字面意思 ...

  6. 在C++中使用openmp进行多线程编程

    在C++中使用openmp进行多线程编程 一.前言 多线程在实际的编程中的重要性不言而喻.对于C++而言,当我们需要使用多线程时,可以使用boost::thread库或者自从C++ 11开始支持的st ...

  7. k8s 探针 exec多个判断条件条件 多个检测条件

    背景 1,之前我们的yaml文件里面有就绪探针. 2,探针是检测一个文件是否生成,生成了说明服务正常. 3,现在要加一个检测,也是一个文件是否存在并且不为空. 4,只有两个条件同时满足了 服务才算正常 ...

  8. Linux centos7 -bash: pstree: 未找到命令

    2021-08-12 1. 命令简介pstree命令将所有行程以树状图显示,树状图将会以 pid (如果有指定) 或是以 init 这个基本行程为根 (root),如果有指定使用者 id,则树状图会只 ...

  9. Git使用教程五

    基于ssh协议(推荐) 该方式与前面https方式相比,只是影响github对于用户的身份鉴权方式,对于git的具体操作(如提交本地.添加注释.提交远程等操作)没有任何影响.   生成公私钥对指令(需 ...

  10. Shell 脚本如何输出帮助信息?

    作者展示了一个技巧,将帮助信息写在 Bash 脚本脚本的头部,然后只要执行"脚本名 + help",就能输出这段帮助信息 https://samizdat.dev/help-mes ...