【问题标题】:Laravel database acces denied rootLaravel 数据库访问被拒绝 root
【发布时间】:2020-08-31 04:27:06
【问题描述】:

我第一次尝试将我的 laravel 项目与我的数据库 mysql 连接起来,但越来越不可能了。我有 ubuntu 20。每当我尝试迁移(php artisan migrate)时,我都会得到这个:

Illuminate\Database\QueryException 

  SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: NO) (SQL: select * from information_schema.tables where table_schema = laravel and table_name = migrations and table_type = 'BASE TABLE')

  at vendor/laravel/framework/src/Illuminate/Database/Connection.php:671
    667|         // If an exception occurs when attempting to run a query, we'll format the error
    668|         // message to include the bindings with SQL, which will make this exception a
    669|         // lot more helpful to the developer instead of just the database's errors.
    670|         catch (Exception $e) {
  > 671|             throw new QueryException(
    672|                 $query, $this->prepareBindings($bindings), $e
    673|             );
    674|         }
    675| 

      +34 vendor frames 
  35  artisan:37
      Illuminate\Foundation\Console\Kernel::handle()

我尝试了一切...我认为我的 .ENV 文件是正确的:

DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=laravel1
DB_USERNAME=root
DB_PASSWORD=1234

我有一个用户“root”并传递“1234”。在控制台中它工作得很好-> sudo mysql -u root -p(然后是 1234)... 我还在 phpmyadmin 中创建了数据库 laravel1,所以没关系... 帮助

【问题讨论】:

    标签: php mysql linux laravel


    【解决方案1】:

    sudo mysql -u root -p 这是一个问题,它应该像mysql -u root -p(没有 sudo)一样工作

    如果没有 root 访问权限,您将无法访问您的数据库来解决我使用的这个问题

    • Step 1 sudo mysql -u root -p ---- 用这个登录然后运行 ​​cmd

    • 第 2 步 > ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '1234'; ---- 在这里您可以随意更改密码

    • 第 3 步 > FLUSH PRIVILEGES;

    它应该可以工作

    【讨论】:

      猜你喜欢
      • 2016-03-02
      • 1970-01-01
      • 1970-01-01
      • 2015-07-04
      • 2013-11-25
      • 2019-04-30
      • 1970-01-01
      • 2020-09-26
      • 1970-01-01
      相关资源
      最近更新 更多