简体   繁体   中英

mysql configuration: access denied error (1045)

I'm having an issue with mysql on a Hyper-V VM on which I'm using Ubuntu. Some possibly relevant specs for what I'm working with:

PHP 7.2.3-1+ubuntu16.04.1+deb.sury.org+1 (cli) 
mysql  Ver 14.14 Distrib 5.7.21, for Linux (x86_64) using  EditLine wrapper
Psy Shell v0.8.18 (PHP 7.2.3-1+ubuntu16.04.1+deb.sury.org+1 — cli)

I'm working on a practice project and very new to coding so I may be missing something completely obvious to a non-novice. When I try:

php artisan migrate

I get the following error:

In Connection.php line 664:

  SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using pas  
  sword: YES) (SQL: select * from information_schema.tables where table_schem  
  a = mytestproject and table_name = migrations)                                     

In PDOConnection.php line 50:

  SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using pas  
  sword: YES)                                                                  

In PDOConnection.php line 46:

  SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using pas  
  sword: YES)  

I've tried to set up my database.php, .env files as follows:

.env file:

APP_ENV=local
APP_DEBUG=true
APP_KEY=
APP_TIMEZONE=UTC

DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=mytestproject
DB_USERNAME=root
DB_PASSWORD=password

REDIS_HOST=127.0.0.1
REDIS_PORT=6379

CACHE_DRIVER=redis
QUEUE_DRIVER=redis

database.php file:

'mysql' => [
    'driver' => 'mysql',
    'host' => env('DB_HOST', 'localhost'),
    'port' => env('DB_PORT', '3306'),
    'database' => env('DB_DATABASE', 'mytestproject'),
    'username' => env('DB_USERNAME', 'root'),
    'password' => env('DB_PASSWORD', 'mypassword'),
    'unix_socket' => env('DB_SOCKET', ' '),
    'charset' => 'utf8mb4',
    'collation' => 'utf8mb4_unicode_ci',
    'prefix' => '',
    'strict' => true,
    'engine' => null,
],

Mysql users:

mysql> SELECT user, host FROM mysql.user;
+------------------+-----------+
| user             | host      |
+------------------+-----------+
| debian-sys-maint | localhost |
| mysql.session    | localhost |
| mysql.sys        | localhost |
| root             | localhost |
+------------------+-----------+
4 rows in set (0.06 sec)

On the basis of my search for this error, I saw many solutions indicating the .env file and database.php file need to be configured properly, which I tried. I tried setting the root user permissions, changing localhost to 127.0.0.1, etc. I've tried everything I've come across suggested on various message boards but am led to believe there may be something special about my setup or something I have yet to check to address this error and move forward with my setup. Any help would be appreciated.

You showed:

In .env file:

DB_PASSWORD=password

And in database.php:

'password' => env('DB_PASSWORD', 'mypassword'),

So where right password is?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM