【发布时间】: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使用你分享的凭证吗?