【问题标题】:I cannot store my data in database. I am tired of getting this localhost error我无法将我的数据存储在数据库中。我厌倦了这个本地主机错误
【发布时间】:2021-09-07 18:00:45
【问题描述】:

我无法将我的数据存储在数据库中。我厌倦了这个本地主机错误 更改密码和创建新数据库对我没有帮助。我尝试了很多可能的方法来解决这个问题

我在终端中遇到错误

PS C:\Programming\Laravel\DailyTaskApp> php artisan migrate
   Illuminate\Database\QueryException 
  SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) (SQL: select * from information_schema.tables where table_schema = daily_task_app and table_name = migrations and table_type = 'BASE TABLE')
  at C:\Programming\Laravel\DailyTaskApp\vendor\laravel\framework\src\Illuminate\Database\Connection.php:692
    688▕         // If an exception occurs when attempting to run a query, we'll format the error
    689▕         // message to include the bindings with SQL, which will make this exception a
    690▕         // lot more helpful to the developer instead of just the database's errors.
    691▕         catch (Exception $e) {
  ➜ 692▕             throw new QueryException(
    693▕                 $query, $this->prepareBindings($bindings), $e
    694▕             );
    695▕         }
    696▕     }
  1   C:\Programming\Laravel\DailyTaskApp\vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.php:70
      PDOException::("SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES)")        
  2   C:\Programming\Laravel\DailyTaskApp\vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.php:70
      PDO::__construct("mysql:host=127.0.0.1;port=3306;dbname=daily_task_app", "root", "root", [])
PS C:\Programming\Laravel\DailyTaskApp>

.env 文件

APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:JB0Pw8lHFyh0yjhyd4fYfY3W1ElXRQ52Xopcv0TWEkc=
APP_DEBUG=true
APP_URL=http://localhost

LOG_CHANNEL=stack
LOG_LEVEL=debug

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=daily_task_app
DB_USERNAME=root
DB_PASSWORD=root

BROADCAST_DRIVER=log
CACHE_DRIVER=file
FILESYSTEM_DRIVER=local
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_LIFETIME=120

phpmyadmin的config.inc.php文件

<?php


/* Authentication type and info */
$cfg['Servers'][$i]['auth_type'] = 'config';
$cfg['Servers'][$i]['user'] = 'root';
$cfg['Servers'][$i]['password'] = 'root';
$cfg['Servers'][$i]['extension'] = 'mysqli';
$cfg['Servers'][$i]['AllowNoPassword'] = true;
$cfg['Lang'] = '';

/* Bind to the localhost ipv4 address and tcp */
$cfg['Servers'][$i]['host'] = 'localhost';
$cfg['Servers'][$i]['connect_type'] = 'tcp';

/* User for advanced features */
$cfg['Servers'] [$i]['controluser'] = 'pma'; 
$cfg['Servers'][$i]['controlpass'] = '';

/* Advanced phpMyAdmin features */

?>

【问题讨论】:

  • 你可以使用 phpMyAdmiin 还是会出错
  • 也许为你的数据库创建另一个用户而不是“root”并在你的应用程序中使用它。
  • 为了让您免于头疼,这是他们在veerasundar.com/blog/… 中找到大部分有用答案的页面。显然有 四个 地方可以设置您的密码。
  • login你的database使用你分享的凭证吗?

标签: php mysql laravel


【解决方案1】:

请对您的 .env 文件进行以下更改。

.env

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=your_db_name
DB_USERNAME=root
DB_PASSWORD=

可能是您的密码应该为空。

在 phpmydamin 中转到 your_db > privalages 以检查用户名和密码

【讨论】:

    【解决方案2】:

    你应该填写mysql root 用户的密码。 如果你忘记了,那么你必须reset

    【讨论】:

    • 这是评论,不是答案。
    猜你喜欢
    • 2017-05-21
    • 2020-08-02
    • 2023-01-27
    • 1970-01-01
    • 2020-08-29
    • 2016-04-27
    • 2013-08-08
    • 1970-01-01
    • 2017-09-15
    相关资源
    最近更新 更多