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

bellpep's avatar

Is it possible to run MySQL in an Ubuntu environment on WSL?

So I'm going through the Laravel 8 From Scratch series but am running into an issue with MySQL in episode 17 (Environment Files and Database Connections).

I'm currently on Windows 10 but running an Ubuntu environment in the Windows Terminal. When I try installing MySQL with homebrew (brew install mysql) and then I run mysql -uroot -p I get the following error:

-bash: /usr/bin/mysql: No such file or directory

I've looked into this issue a bit and found a few people saying you're supposed to start mysql first with brew services start mysql but when I try running this I get this error:

Failed to connect to bus: No medium found
Error: Failure while executing; `/home/linuxbrew/.linuxbrew/bin/systemctl --user daemon-reload` exited with 1.

Looking even further into this issue I found that people were saying you shouldn't be using homebrew to install mysql in an ubuntu environment but instead you should be using sudo apt-get install mysql-server. So I do this, then start mysql using sudo /etc/init.d/mysql start which works. But then when I run sudo mysql -uroot -p I run into the following error:

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

Here's the DB section of my .env file:

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

All commands I'm running are being run from the Laravel project directory /home/anthony726/my-laravel-blog in the Windows terminal.

If anyone has any insight on this issue I'd appreciate it a lot! I've been trying to solve this for 2 days straight with no luck.

0 likes
5 replies
sr57's avatar

@bellpep

Welcome to Laracast.

Did you really run this command "sudo mysql -uroot -p blog" ?

Normally, "-p" asks you for a password ...

bellpep's avatar

@sr57 Yep I ran that. Here's what it looks like:

sudo mysql -uroot -p blog
[sudo] password for anthony726:
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
bellpep's avatar

@sr57 Thank you! This got me past the access denied error. But now when I create the database blog and then try to run php artisan migrate I get the following error:

 Illuminate\Database\QueryException

  SQLSTATE[HY000]: General error: 1356 View 'information_schema.TABLES' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them (SQL: select * from information_schema.tables where table_schema = blog and table_name = migrations and table_type = 'BASE TABLE')

  at vendor/laravel/framework/src/Illuminate/Database/Connection.php:742
    738▕         // If an exception occurs when attempting to run a query, we'll format the error
    739▕         // message to include the bindings with SQL, which will make this exception a
    740▕         // lot more helpful to the developer instead of just the database's errors.
    741▕         catch (Exception $e) {
  ➜ 742▕             throw new QueryException(
    743▕                 $query, $this->prepareBindings($bindings), $e
    744▕             );
    745▕         }
    746▕     }

      +25 vendor frames
  26  artisan:37
      Illuminate\Foundation\Console\Kernel::handle()
sr57's avatar

@bellpep

It's another question close this one (chose the best anwser) and open a new one.

Don't forget to share also your migration file, the error seems to come form it ...

1 like

Please or to participate in this conversation.