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?

0
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.

3
  • It's a fresh install of Ubuntu. And this worked!!! Turns out I just had to delete the root user and recreate it and flush privileges. Now php artisan migrate works. THANKS! – qotsa42 Jun 23 '18 at 4:19
  • Glad it helped! :) – chrisidakwo Jul 4 '18 at 13:03
  • A link to a solution is welcome, but please ensure your answer is useful without it: add context around the link so your fellow users will have some idea what it is and why it’s there, then quote the most relevant part of the page you're linking to in case the target page is unavailable. Answers that are little more than a link may be deleted. – Mithical Jul 29 '18 at 18:05

Not the answer you're looking for? Browse other questions tagged or ask your own question.