使用CakePHP时无法连接到本地MySQL数据库

时间:2015-05-06 15:51:02

标签: php mysql cakephp

我有这个配置:

'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'],
],

我有一个本地MySql数据库,其上面已经输入了相同的登录参数,但是在新安装的CakePHP的首页上告诉我下一步:

  

CakePHP无法连接到数据库。

     

无法建立与数据库的连接:SQLSTATE [HY000]   [1045]拒绝访问用户&root;&#39; @&#39; localhost&#39; (使用密码:是)

我该如何解决?我通过My​​Sql Workbench与此登录名和密码连接得很好。什么阻止Cake框架做同样的事情?

2 个答案:

答案 0 :(得分:0)

您是否加载了模块,使您能够在配置中连接到MYSQL。基本上你需要确保你的php.ini有以下行注释 延长=激活php_mysql.dll 延长= php_mysqli.dll

答案 1 :(得分:-1)

当用户名或密码不正确时,通常会显示此错误消息。

{{1}}

请确保用户root的密码为root。

在MySQL中,默认root的密码为空。

相关问题