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

murilo's avatar
Level 10

Error connecting database

I created a ubuntu server for laravel . I have a root user , that I added in .env file -

DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=mywebsite
DB_USERNAME=root
DB_PASSWORD=mypassword


then I migrated the database with the command -

php artisan migrate

It migrated ok . BUT , it is givving this error -

Illuminate\Database\QueryException
SQLSTATE[HY000] [1698] Access denied for user 'root'@'localhost' (SQL: select `id`, `title`from `posts` order by `id` asc)

It is saying that I dont have permission with my user root , to select . BUT I had permission to migrate . how could I give permission to it ?

Thanks

0 likes
4 replies
siangboon's avatar

try clear the cache, or simply deletes bootstrap/cache/config.php file.. restart your web service...

php artisan config:clear 
murilo's avatar
Level 10

hello @siangboon , I have tried that , but it didnt work . The Root user It is able to migrate the database BUT it is not able to select a table . It had never happened that with me .

sauravs012's avatar

Some systems like Ubuntu, mysql is using by default the UNIX auth_socket plugin. Your problem will solved by setting the plugin value in user tables.

mysql> USE mysql;
mysql> UPDATE user SET plugin='mysql_native_password' WHERE User='root';
mysql> FLUSH PRIVILEGES;
mysql> exit;
$ service mysql restart
murilo's avatar
Level 10

hello @sauravs012 , thanks for the help . but is giving this error -

ERROR 1142 (42000): UPDATE command denied to user 'root'@'localhost' for table 'user'

Please or to participate in this conversation.