0

I setup a new dev environment on WSL2 (Windows Subsystem for Linux) with Ubuntu 20.04.

A generic LAMP stack, Apache2, PHP 7.3, and MariaDB for the mysql server.

When I try to run php artisan install on my Laravel app, I get the following error

In Connection.php line 664:

  SQLSTATE[HY000] [1698] Access denied for user 'root'@'localhost' (SQL: select * from information_schema.tables where table_schema
  = dev_database and table_name = default_migrations and table_type = 'BASE TABLE')

AND

SQLSTATE[HY000] [1698] Access denied for user 'root'@'localhost'

I have entered the correct mysql password but not sure what this error means.

I suspect it might be a permission issue with folders or access to DB so I looked up the processes to see how MySQL is being run.

After I run ps aux, I get the following (not sure if this is related but I have 3 proccesses for DB)

root     24328  0.0  0.0   2612  1872 pts/1    S    Aug30   0:00 /bin/sh /usr/bin/mysqld_safe
mysql    24445  0.0  1.3 1775800 88096 pts/1   Sl   Aug30   0:03 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=
root     24446  0.0  0.0   9720  1000 pts/1    S    Aug30   0:00 logger -t mysqld -p daemon error
IEnumerable
  • 3,230
  • 11
  • 42
  • 72
  • Did you reload caches: `FLUSH PRIVILEGES;` or, how did you get onto the server in firstplace? Use the same credentials in PHP. – Daniel W. Aug 30 '20 at 15:12
  • Yes, and still get the same error :( – IEnumerable Aug 30 '20 at 15:13
  • 1
    How did you grant `root@localhost` or `root@%` ? How do you login to mysql through the shell? – Daniel W. Aug 30 '20 at 15:14
  • i logged in just as `sudo mysql` – IEnumerable Aug 30 '20 at 15:18
  • 2
    and also `GRANT ALL ON *.* TO 'admin'@'localhost' IDENTIFIED BY 'password' WITH GRANT OPTION;` – IEnumerable Aug 30 '20 at 15:19
  • 2
    You granted to `admin` but you try to login using `root`. If you just use `mysql`, use `cat ~/.my.cnf` to show local mysql config which might contain credentials. – Daniel W. Aug 30 '20 at 15:43
  • @Daniel-W, You pointed something out to me earlier, I realized I couldnt login via `mysql -uroot -p`, So I found this article https://stackoverflow.com/questions/39281594/error-1698-28000-access-denied-for-user-rootlocalhost – IEnumerable Aug 30 '20 at 15:46
  • What does the command `php artisan install` do? I haven't heard about it before. Do you mean `php artisan migrate:install` ? Or `composer install` ? Which version of Laravel are you using? – Prince Dorcis Aug 30 '20 at 15:46
  • It turns out my system was using `unix_socket`. I dont understand all these options but as referred to the otehr page I executed `UPDATE user SET plugin='mysql_native_password' WHERE User='root';` - Still testing now – IEnumerable Aug 30 '20 at 15:47
  • MySQL is interpreting `localhost` synonym for the local socket, it's trying `/run/mysqld.sock` or similiar so thats ok. A default installation should just work, you don't need to hassle with authentication plugins. Just use the correct username and password. – Daniel W. Aug 30 '20 at 17:11

1 Answers1

1

That means you can't just run mysql -u root anymore and have to do sudo mysql -u root instead

To make it work you'll have to create a new user with the required privileges and use that instead.

See this answer for more details.