SQLSTATE [HY000] [1045]使用CakePhp拒绝用户'username'@'localhost'的访问 [英] SQLSTATE[HY000] [1045] Access denied for user 'username'@'localhost' using CakePhp

查看:3047
本文介绍了SQLSTATE [HY000] [1045]使用CakePhp拒绝用户'username'@'localhost'的访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是PHP和CakePHP的新手。使用CakePhp连接数据库时发现问题。

I am new to PHP and CakePHP. Finding problems while wiring my database using CakePhp.

以下是我的应用程序配置。
我在Bitnami WAMP堆栈5.4.40-0
我使用CakePhp 3.0.4创建一个web mvc应用程序

Below is my app configuration. I am on Bitnami WAMP stack 5.4.40-0 I am using CakePhp 3.0.4 to create a web mvc application

in my app.php file

Entry for datasources in My app.php file

/**
 * Connection information used by the ORM to connect
 * to your application's datastores.
 * Drivers include Mysql Postgres Sqlite Sqlserver
 * See vendor\cakephp\cakephp\src\Database\Driver for complete list
 */
'Datasources' => [
    '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' => 'test2',
        'password' => 'computer',
        'database' => 'jobs',
        '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'],
    ],

数据库表,根据CakePp约定调用作业。用户test2具有与root admin相同的全局权限。

I have already created a database table called jobs according to CakePhp conventions. User test2 has global privileges same like root admin.

但是当我运行bake all命令时。我收到以下错误

But when I am running the bake all command. I am getting the following error

2015-07-01 06:24:56 Error: [PDOException] SQLSTATE[HY000] [1045] Access denied for user 'test2'@'localhost' (using password: YES)
Stack Trace:
C:\Bitnami\wampstack-5.4.40-0\apache2\htdocs\myjobs\vendor\cakephp\cakephp\src\Database\Driver\PDODriverTrait.php(48): PDO->__construct('mysql:host=127....', 'test2', 'computer', Array)
C:\Bitnami\wampstack-5.4.40-0\apache2\htdocs\myjobs\vendor\cakephp\cakephp\src\Database\Driver\Mysql.php(89): Cake\Database\Driver\Mysql->_connect('mysql:host=127....', Array)
C:\Bitnami\wampstack-5.4.40-0\apache2\htdocs\myjobs\vendor\cakephp\cakephp\src\Database\Schema\BaseSchema.php(46): Cake\Database\Driver\Mysql->connect()

PROBLEM SOLVED(UPDATE) strong>

PROBLEM SOLVED (UPDATE)

我按照Ankit和Spencer的指示。

I followed Ankit and Spencer's directions.

我遇到了几个问题。


  1. 我的用户的主机不是localhost,它是一个通配符%。更改了,然后mysql开始拒绝连接。

  1. Host of my user was not localhost, it was a wildcard %. Changed that, then mysql started refusing connections.

我禁用了防火墙,发现端口不同于3306.因此更改了app.php中的条目。现在我的应用程序被烘焙了:)

I disabled my firewall and found that the port was different from 3306. So changed the entry in app.php. Now my application is baked :)


推荐答案

您使用的密码与MySQL认为您连接的用户的密码不匹配,或者匹配的MySQL用户不存在(尚未创建)。

That error message usually means that either the password you are using doesn't match what MySQL thinks the password should be for the user you're connecting as, or a matching MySQL user doesn't exist (hasn't been created).

在MySQL中,用户由用户名( test2 )和主机( localhost )。

In MySQL, a user is identified by both a username (test2) and a host (localhost).

您将得到的错误信息标识用户(test2)和 host (localhost)values ...

The error message you are getting identify the user (test2) and host (localhost) values...

  'test2'@'localhost'

使用此查询从您可以连接的客户端检查该用户是否存在:

Check to see if that user exists, using this query from a client you can connect from:

 SELECT user, host FROM mysql.user

您正在为用户查找 test2 的行,并为主机查找 localhost

You're looking for a row that has test2 for user, and localhost for host.

 user     host       
 -------  -----------
 test2     127.0.0.1  
 test2     ::1        
 test2     localhost  

如果该行不存在,那么可以将主机设置为的通配符值,以匹配任何不匹配的主机。

If that row doesn't exist, then the host may be set to wildcard value of %, to match any other host that isn't a match.

如果该行存在,那么密码可能不匹配。您可以更改密码(如果您以具有足够权限的用户身份连接,例如 root

If the row exists, then the password may not match. You can change the password (if you're connected as a user with sufficient privileges, e.g. root

 SET PASSWORD FOR 'test2'@'localhost' = PASSWORD('mysecretcleartextpassword')

同时验证用户对数据库中对象的权限。

Also verify that the user has privileges on objects in the database.

 GRANT SELECT ON jobs.* TO 'test2'@'localhost' 

这篇关于SQLSTATE [HY000] [1045]使用CakePhp拒绝用户'username'@'localhost'的访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆