Tôi mới sử dụng PHP và CakePHP. Tìm kiếm sự cố khi kết nối cơ sở dữ liệu của tôi bằng CakePhp.SQLSTATE [HY000] [1045] Truy cập bị từ chối đối với tên người dùng 'tên người dùng' @ 'localhost' bằng CakePhp
Dưới đây là cấu hình ứng dụng của tôi. Tôi đang trên BitNami wamp ngăn xếp 5.4.40-0 Tôi đang sử dụng CakePHP 3.0.4 để tạo ra một trang web ứng dụng MVC
Entry for datasources trong tập tin app.php My
/**
* 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'],
],
Tôi đã tạo một bảng cơ sở dữ liệu được gọi là các công việc theo các quy ước của CakePhp. Người dùng test2 có các đặc quyền chung giống như quản trị viên gốc.
Nhưng khi tôi chạy lệnh nướng tất cả. Tôi nhận được lỗi sau
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()
vấn đề giải quyết (UPDATE)
Tôi đi theo Ankit và hướng Spencer.
Tôi gặp một số vấn đề.
Máy chủ của người dùng của tôi không phải là máy chủ cục bộ, đó là ký tự đại diện%. Thay đổi điều đó, sau đó mysql bắt đầu từ chối kết nối.
Tôi đã tắt tường lửa và thấy rằng cổng khác với 3306. Vì vậy, đã thay đổi mục nhập trong app.php. Bây giờ ứng dụng của tôi được nướng :)
'Truy cập bị từ chối cho người dùng 'test2' @ 'localhost' (sử dụng mật khẩu: YES)' khá rõ ràng. _Does_ người dùng test2 có quyền truy cập không? I E. hiện công việc này: 'mysql -utest2 -pcomputer jobs'? – AD7six
lạ, thay đổi '%' thành 'localhost' thực sự làm việc cho tôi ... Ngoài ra nó có thể tạo một người dùng khác - xóa một người dùng với máy chủ'% ' –
Khởi động lại MySQL sau những thay đổi đó là đóng băng trên bánh. – dakab