Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

rickyspires's avatar

Access denied when running php artisan migrate

Access denied when running php artisan migrate

$ php artisan migrate                                                               
[PDOException]                                                               
SQLSTATE[HY000] [1045] Access denied for user 'rickyspires'@'localhost' (us  
ing password: YES)  

I think it is because I recently changed my database login . How can i give my new user access permissions.

DB_HOST=localhost
DB_DATABASE=rickyspires-laravel
DB_USERNAME=rickyspires
DB_PASSWORD=b**********4

Thanks

0 likes
15 replies
pixelpeter's avatar

If you have the correct values in your .env file maybe you have the config cached.

You can clear it (to get the new values) with:

php artisan config:clear
2 likes
rickyspires's avatar

thanks but that did not work

$ php artisan config:clear
    Configuration cache cleared!
$ php artisan migrate
                                                    
[PDOException]                                                               
SQLSTATE[HY000] [1045] Access denied for user 'rickyspires'@'localhost' (us  
ing password: YES)                                                           
                 
SachinAgarwal's avatar

@rickyspires probably you are mistyping the password or database name or username. Check the typos and even permissions on the database.

rickyspires's avatar

Hello. Not really. that question i couldn't connect to the sequel pro database. this question i can get in to sequel pro and i can ssh but every time in try and do php artisan migrate i get an error

[PDOException]                                                               
SQLSTATE[HY000] [1045] Access denied for user 'homestead'@'localhost' (usin  
g password: YES)                                                             
    

I have changed all my settings back to the default settings and i am still having the same trouble. these are my settings:

Homestead.yaml databases: - rs-homestead - rs-rickyspires-laravel

variables:
    - key: APP_ENV
    value: local
    

.env DB_CONNECTION=mysql DB_HOST=localhost DB_DATABASE=homestead DB_USERNAME=homestead DB_PASSWORD=secret

sequel pro

- standard
host: 127.0.0.1
username: homestead
password: secret
database: homestead
port: 33060

users

homestead 777
% = 777
0.0.0.0 = 777

i also tried adding 127.0.0.1, ::1, homestead and localhost all as 777

but i still can not get in to to migrate :(

any ideas any one ?

mstnorris's avatar

Well what are your database credentials? Are you even using Homestead?

If this works from Sequel Pro:

host: 127.0.0.1
username: homestead
password: secret
database: homestead
port: 33060

Then you should be able to use:

host: localhost // or 192.168.10.10
username: homestead
password: secret
database: homestead
rickyspires's avatar

hi all. fixed it . I didn't realize that i have to ssh in the cd to my project and run it from there. ooops . thanks for all your help. r.

cloud4bpm's avatar

Maybe are you trying to connect outside the ssh homestead connection? Sometimes I failed on this process because I'm trying to use without running homestead up (or vagrant up command) or I forgot execute the homestead ssh command before running any mysql or migration command, then the session is not started and any mysql command would be executed on your local machine (wamp, xamp, mamp, ...)

mstnorris's avatar

@rickyspires no disrespect but take a look at your other question you asked yesterday, I already said that you needed to do that!

Well you are loading up Homestead, but you're not SSHing into it, so you're just using your Mac's mysql database (not Homestead's)

Please mark both questions as answered; appropriately.

T!m's avatar

Change the DB cred. in Database file and in .env file. Hope this works

Sam T.'s avatar

I had this issue and it turned out I was mis-typing my password!!! Double check credentials always! THX

scloutca's avatar

I know this might be an old thread, but I had the same problem and realized that the problem was in the way my password was written in my .env file. Putting the password between double quotes made it work. Probably a special character in my password was making it fail.

DB_PASSWORD="*******"

arundot93's avatar

Clearing both config and cache seemed to work well for me. So try running both config:clear and cache:clear

Victor Paredes's avatar

When I got this error:

SQLSTATE[HY000] [1698] Access denied for user 'root'@'localhost' (SQL: select * from information_schema.tables where table_schema = database_name and table_name = migrations and table_type = 'BASE TABLE')

I solved it by simply allowing access in MariaDB:

GRANT ALL ON database_name.* TO root@localhost IDENTIFIED BY '';

My .env file looks like this, so you can connect the dots, if you need context:

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=database_name
DB_USERNAME=root
DB_PASSWORD=

I hope this helps save someone time in the future. I was trying to figure this out for quite a while!

Please or to participate in this conversation.