SQLSTATE[HY000] [1045] 使用 Mac Os 和 MAMP 拒绝用户“root”@“localhost”使用密码:NO的访问

问题描述

我使用的是 mac OS,并由 MAMP 托管

当我输入 PHP artisan migratesudo PHP artisan migrate 时出现问题

首先我遇到了 CONNECTION REFUSED 问题,所以我将 DB_SOCKET=/Applications/MAMP/tmp/MysqL/MysqL.sock 添加到我的 .env 文件中,然后它更改为 ACCESS DENIED

我的 .env

APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:3dkG/ka7V81mIaIK34T/pOn10/J7n65q/O21K2slsWs=
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=laravel_db
DB_USERNAME=root
DB_PASSWORD=
DB_SOCKET=/Applications/MAMP/tmp/MysqL/MysqL.sock


broADCAST_DRIVER=log
CACHE_DRIVER=file
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_LIFETIME=120

MEMCACHED_HOST=127.0.0.1

REdis_HOST=127.0.0.1
REdis_PASSWORD=null
REdis_PORT=6379

MAIL_MAILER=smtp
MAIL_HOST=mailhog
MAIL_PORT=1025
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS=null
MAIL_FROM_NAME="${APP_NAME}"

AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=

PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_APP_CLUSTER=mt1

MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"

和我的database.PHP

<?PHP

use Illuminate\Support\Str;

return [

    /*
    |--------------------------------------------------------------------------
    | Default Database Connection Name
    |--------------------------------------------------------------------------
    |
    | Here you may specify which of the database connections below you wish
    | to use as your default connection for all database work. Of course
    | you may use many connections at once using the Database library.
    |
    */

    'default' => env('DB_CONNECTION','MysqL'),/*
    |--------------------------------------------------------------------------
    | Database Connections
    |--------------------------------------------------------------------------
    |
    | Here are each of the database connections setup for your application.
    | Of course,examples of configuring each database platform that is
    | supported by Laravel is shown below to make development simple.
    |
    |
    | All database work in Laravel is done through the PHP PDO facilities
    | so make sure you have the driver for your particular database of
    | choice installed on your machine before you begin development.
    |
    */

    'connections' => [

        'sqlite' => [
            'driver' => 'sqlite','url' => env('DATABASE_URL'),'database' => env('DB_DATABASE',database_path('database.sqlite')),'prefix' => '','foreign_key_constraints' => env('DB_FOREIGN_KEYS',true),],'MysqL' => [
            'driver' => 'MysqL','host' => env('DB_HOST','127.0.0.1'),'port' => env('DB_PORT','3306'),'forge'),'username' => env('DB_USERNAME','password' => env('DB_PASSWORD',''),'unix_socket' => env('DB_SOCKET','charset' => 'utf8mb4','collation' => 'utf8mb4_unicode_ci','prefix_indexes' => true,'strict' => true,'engine' => null,'options' => extension_loaded('pdo_MysqL') ? array_filter([
                PDO::MysqL_ATTR_SSL_CA => env('MysqL_ATTR_SSL_CA'),]) : [],'pgsql' => [
            'driver' => 'pgsql','5432'),'charset' => 'utf8','schema' => 'public','sslmode' => 'prefer','sqlsrv' => [
            'driver' => 'sqlsrv','localhost'),'1433'),/*
    |--------------------------------------------------------------------------
    | Migration Repository Table
    |--------------------------------------------------------------------------
    |
    | This table keeps track of all the migrations that have already run for
    | your application. Using this information,we can determine which of
    | the migrations on disk haven't actually been run in the database.
    |
    */

    'migrations' => 'migrations',/*
    |--------------------------------------------------------------------------
    | Redis Databases
    |--------------------------------------------------------------------------
    |
    | Redis is an open source,fast,and advanced key-value store that also
    | provides a richer body of commands than a typical key-value system
    | such as APC or Memcached. Laravel makes it easy to dig right in.
    |
    */

    'redis' => [

        'client' => env('REdis_CLIENT','PHPredis'),'options' => [
            'cluster' => env('REdis_CLUSTER','redis'),'prefix' => env('REdis_PREFIX',Str::slug(env('APP_NAME','laravel'),'_').'_database_'),'default' => [
            'url' => env('REdis_URL'),'host' => env('REdis_HOST','password' => env('REdis_PASSWORD',null),'port' => env('REdis_PORT','6379'),'database' => env('REdis_DB','0'),'cache' => [
            'url' => env('REdis_URL'),'database' => env('REdis_CACHE_DB','1'),];

任何帮助将不胜感激,我是新手,所以我真的被困住了,在互联网上找不到任何东西,每个人都在使用 ubuntu linux 而不是 mac os

编辑

我输入了密码“root”,问题从拒绝访问改为

sqlSTATE[HY000] [1049] UnkNown database 'laravel_db' (sql: select * from information_schema.tables where table_schema = laravel_db and table_name = migrations and table_type = 'BASE TABLE')

这是我的 PHPmyadmin 页面

enter image description here

解决方法

正如提到的 NanThiyagan,我只需要在 localhost/8888/phpmyadmin 中创建一个与 .env 或 database.php 同名的数据库

你需要创建一个名为 laravel_db 的数据库 – NanThiyagan

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...