-3

I'm trying to deploy my cakephp project on my virtual machine.

When I type mysql -u root -p on my VM it works but cakephp seems to not have access to this.

Here is how my DB config looks like:

'Datasources' => [
    'default' => [
        'className' => 'Cake\Database\Connection',
        'driver' => 'Cake\Database\Driver\Mysql',
        'persistent' => false,
        'host' => '127.0.0.1',
        //'port' => 'non_standard_port_number',
        'username' => 'root',
        'password' => '',
        'database' => 'webarena',
        'encoding' => 'utf8',
        'timezone' => 'UTC',
        'flags' => [],
        'cacheMetadata' => true,
        'log' => false,
        'quoteIdentifiers' => false,
        'url' => env('DATABASE_URL', null),
    ],

And I've got the following error:

SQLSTATE[HY000] [1698] Access denied for user 'root'@'localhost'

So I tried to set a new password by doing so:

mysql> UPDATE mysql.user SET Password=PASSWORD('SecurePassword') WHERE
User='root';
mysql> FLUSH PRIVILEGES;
mysql> EXIT

But still doesn't work.

I can also type mysql and it works? How's that possible?

Kathryn Schutte
  • 95
  • 1
  • 1
  • 6
  • 4
    Possible duplicate of [Access denied for user 'root@localhost' (using password:NO)](https://stackoverflow.com/questions/2995054/access-denied-for-user-rootlocalhost-using-passwordno) – BenRoob Oct 30 '17 at 14:01

1 Answers1

0

Your Question is unclear, especially the title word "locally". My Answer follows one interpretation; BenRoob's "dup of" follows another.

"localhost" is a different "host" from those with an IP address or host name. The GRANT tables make a distinction. I think you are tripping over such.

    GRANT ... to 'user'@'localhost' ...

lets user get in when running from the same machine. '127.0.0.1' and '::' are probably synonyms for 'localhost'.

    GRANT ... to 'user'@'%' ...

lets user get in from any other machine. (For security reasons, '%' is not advised.)

Rick James
  • 135,179
  • 13
  • 127
  • 222