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

rickyspires's avatar

Access denied! when changing database details ?

Hello. I am having trouble changing my database details. If I use the defaul credentials it works fine and in can get in to it by sequal pro and ssh but if i try changing the database details in get Access Denied. what am i doing wrong.

my database.php looks the same:

    'mysql' => [
        'driver'    => 'mysql',
        'host'      => env('DB_HOST', 'localhost'),
        'database'  => env('DB_DATABASE', 'forge'),
        'username'  => env('DB_USERNAME', 'forge'),
        'password'  => env('DB_PASSWORD', ''),
        'charset'   => 'utf8',
        'collation' => 'utf8_unicode_ci',
        'prefix'    => '',
        'strict'    => false,
    ],

but i want to change my env file from this

DB_HOST=localhost
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret

to this

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

my sequel pro looks like this

Name: myname
Host: 127.0.0.1
Username: myname
Password: b********4
Database: myname-laravel
Port: 33060

but i get Unable to connect to host 127.0.0.1 because access was denied.

???

thanks

0 likes
5 replies
mstnorris's avatar

@rickyspires have you change the database credentials from within the database itself; *and does the database actually exist?

Also, are you using a Mac or Windows PC, Homestead or other like MAMP, WAMP etc?

Have you set your DB_CONNECTION in the .env file to be "mysql" ? Or does it default to "mysql" in your config/database.php? like so:

'default' => env('DB_CONNECTION', 'mysql'),

I'm on a Mac using Homestead so I use:

DB_CONNECTION=mysql
DB_HOST=192.168.10.10
DB_DATABASE=myname-laravel
DB_USERNAME=myname
DB_PASSWORD=b********4

I also use Sequel Pro; so my connection looks like this:

mstnorris's avatar

Are you using Homestead then? If so, it is super easy, you can do it two ways:

  1. While you're in Sequel Pro just create a new Database from the "Database" menu at the top. (This will be persisted even if you run homestead provision again in the future).
  2. Edit your Homestead.yaml file and add the database to that. Then just run homestead provision from the command line. (Each time you run homestead provision your databases will be reset - so you will lose data. If you're just testing and you're using seeders then this probably won't be an issue).

$ homestead up $ mysql -u homestead -p Enter password: secret ERROR 1045 (28000): Access denied for user 'homestead'@'localhost' (using password: YES) What is going on :(

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)

  1. Run homestead up
  2. Run homestead ssh
  3. You can do what you did above, however it is easier to do it one o the two ways I showed you.
rickyspires's avatar

Thanks for all your help. I have it all working now :)

Please or to participate in this conversation.