I am new to PHP and CakePHP. I am finding problems while wiring my database using CakePHP.
Below is my application configuration.
I am on Bitnami WAMP stack
That error message usually means that either the password we are using doesn't match what MySQL thinks the password should be for the user we're connecting as, or a matching MySQL user doesn't exist (hasn't been created).
In MySQL, a user is identified by both a username ("test2") and a host ("localhost").
The error message identifies the user ("test2") and the host ("localhost") values...
'test2'@'localhost'
We can check to see if the user exists, using this query from a client we can connect from:
SELECT user, host FROM mysql.user
We're looking for a row that has "test2" for user, and "localhost" for host.
user host
------- -----------
test2 127.0.0.1 cleanup
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.
If the row exists, then the password may not match. We can change the password (if we're connected as a user with sufficient privileges, e.g. root
SET PASSWORD FOR 'test2'@'localhost' = PASSWORD('mysecretcleartextpassword')
We can also verify that the user has privileges on objects in the database.
GRANT SELECT ON jobs.* TO 'test2'@'localhost'
EDIT
If we make changes to mysql privilege tables with DML operations (INSERT,UPDATE,DELETE), those changes will not take effect until MySQL re-reads the tables. We can make changes effective by forcing a re-read with a FLUSH PRIVILEGES
statement, executed by a privileged user.
I saw it's solved, but I still want to share a solution which worked for me.
.env file:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=[your database name]
DB_USERNAME=[your MySQL username]
DB_PASSWORD=[your MySQL password]
MySQL admin:
SELECT user, host FROM mysql.user
Thank you, spencer7593
Console:
php artisan cache:clear
php artisan config:cache
Now it works for me.
Laracasts answers
If you use MAMP, you might have to set the socket: unix_socket: /Applications/MAMP/tmp/mysql/mysql.sock
I want to add to the answers posted on above that none of the solutions proposed here worked for me. My WAMP, is working on port 3308 instead of 3306 which is what it is installed by default. I found out that when working in a local environment, if you are using mysqladmin in your computer (for testing environment), and if you are working with port other than 3306, you must define your variable DB_SERVER with the value localhost:NumberOfThePort, so it will look like the following: define("DB_SERVER", "localhost:3308"). You can obtain this value by right-clicking on the WAMP icon in your taskbar (on the hidden icons section) and select Tools. You will see the section: "Port used by MySQL: NumberOfThePort"
This will fix your connection to your database.
This was the error I got: Error: SQLSTATE[HY1045] Access denied for user 'username'@'localhost' on line X.
I hope this helps you out.
:)
Check Following Things