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

qotsa's avatar
Level 1

Setting up valet for local environment. Correct user/pass for .env file but getting "access denied" errors when running php artisan migrate

Hi, I've been following the Laracasts series and am trying to run php artisan migrate in the root directory of my laravel project and when i do i get the following error:

 Illuminate\Database\QueryException  : SQLSTATE[HY000] [1698] Access denied for user 'root'@'localhost' (SQL: select * from information_schema.tables where table_schema = blog and table_name = migrations)

at /home/david/Sites/blog/vendor/laravel/framework/src/Illuminate/Database/Connection.php:664
  660|         // If an exception occurs when attempting to run a query, we'll format the error
  661|         // message to include the bindings with SQL, which will make this exception a
  662|         // lot more helpful to the developer instead of just the database's errors.
  663|         catch (Exception $e) {
> 664|             throw new QueryException(
  665|                 $query, $this->prepareBindings($bindings), $e
  666|             );
  667|         }
  668| 

Exception trace:

1   PDOException::("SQLSTATE[HY000] [1698] Access denied for user 'root'@'localhost'")
    /home/david/Sites/blog/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:68

2   PDO::__construct("mysql:host=127.0.0.1;port=3306;dbname=blog", "root", "", [])
    /home/david/Sites/blog/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:68

it seems pretty clear to me that the .env file doesn't contain the right information... but it does. here's my .env for mysql database:

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

Database I'm trying to enter is called blog, and the user name is root and the password is blank. That's how I access mysql on my machine... `sudo mysql -uroot -p' and it logs me right in.

Any idea what might be going wrong?

0 likes
3 replies
Snapey's avatar

are you running any sort of virtualisation (eg homestead) where you might have more than one instance of mysql available to you?

have you changed anything in config/database.php ?

1 like
qotsa's avatar
Level 1

I have not changed anything in config/database.php. There shouldn't be any other virtualisations running... This is a fresh install of Ubuntu 18.04 and I didn't even install mysql-server until I got to this part of the video.

Is there a way to check if I do for some reason have more than one mysql instance running?

Please or to participate in this conversation.