简体   繁体   中英

Can't connect to local MySQL database while using CakePHP

I have this config:

'default' => [
    'className' => 'Cake\Database\Connection',
    'driver' => 'Cake\Database\Driver\Mysql',
    'persistent' => false,
    'host' => 'localhost',
    /**
     * CakePHP will use the default DB port based on the driver selected
     * MySQL on MAMP uses port 8889, MAMP users will want to uncomment
     * the following line and set the port accordingly
     */
    //'port' => 'nonstandard_port_number',
    'username' => 'root',
    'password' => 'root',
    'database' => 'addressbook',
    'encoding' => 'utf8',
    'timezone' => 'UTC',
    'cacheMetadata' => true,

    /**
     * Set identifier quoting to true if you are using reserved words or
     * special characters in your table or column names. Enabling this
     * setting will result in queries built using the Query Builder having
     * identifiers quoted when creating SQL. It should be noted that this
     * decreases performance because each query needs to be traversed and
     * manipulated before being executed.
     */
    'quoteIdentifiers' => false,

    /**
     * During development, if using MySQL < 5.6, uncommenting the
     * following line could boost the speed at which schema metadata is
     * fetched from the database. It can also be set directly with the
     * mysql configuration directive 'innodb_stats_on_metadata = 0'
     * which is the recommended value in production environments
     */
    //'init' => ['SET GLOBAL innodb_stats_on_metadata = 0'],
],

And i have a local MySql Database with same login params that i've entered above, but on the front page of freshly installed CakePHP in tells me next:

CakePHP is NOT able to connect to the database.

Connection to database could not be established: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES)

How can i fix it? I'm connecting just fine with this login and password via MySql Workbench. What's stopping Cake framework from doing the same?

did you load the module that enable you to connect to the MYSQL in your your configuration. basically you need to make sure that your php.ini has the following line commented extension=php_mysql.dll extension=php_mysqli.dll

This error message often is showed when username or password is not correct.

CakePHP is NOT able to connect to the database.

Connection to database could not be established: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES)

So that please make sure password of user root is root.

In MySQL, Default root's password is empty.

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