3

This is similar to this question but my situation is a little different.

I have laravel, composer, and valet running on Ubuntu 18.04. I'm trying to run php artisan migrate and it throws errors related to being unable to connect to the mysql database.

 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?

qotsa42
  • 43

1 Answers1

2

Edit your .env file by adding the DATABASE_URL if it's not already there and set it to the following:

DATABASE_URL=mysql://user:password@127.0.0.1/dbname

mysql can be replaced by any other driver depending on the one you use.