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

rlw92's avatar
Level 1

Laravel - mysql - php artisan not working

Hi there newbie to php and laravel here.

Am trying to run php artisan migrate but am encountering this error:

Illuminate\Database\QueryException

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

Can anyone help me please? Can give more information if needed.

Thank you.

0 likes
6 replies
Snapey's avatar

The message is normally correct. You cannot connect to your database using the root user.

You just need to check your credentials in your env file, and then run artisan config:clear

rlw92's avatar
Level 1

these are the credentials in my env file: DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE=demo DB_USERNAME=root DB_PASSWORD=

i ran the artisan clear config and it said cache cleared but the same error is coming up as before when I run the php artisan migrate command???

amitsolanki24_'s avatar

@rlw92 Something happened with your database connection please check your Database credentials inside your .env file

rlw92's avatar
Level 1

these are my database credentials in my env file: DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE=demo DB_USERNAME=root DB_PASSWORD=

as i said am a complete newbie to all of this how do i go about checking these are correct? Because I was just following a tutorial and this popped up and now i cant progress.

gych's avatar

@rlw92 Are you having these issues locally or on production?

If its local it seems like you're having issues with the setup of the root account. Check the user accounts for your database and see if the root user exists and has the right permissions. If you use mysql with phpmyadmin client It should be reachable via this link: http://localhost/phpmyadmin/index.php?route=/server/privileges&viewing_mode=server

If you have this issue on production you need to add the correct db user credentials in your env file (not root).

1 like
JussiMannisto's avatar

@rlw92 In a typical mysql setup you cannot use the root user like @snapey said. You'd need superuser privileges for that, which your web server user doesn't have (or SHOULD NOT have).

You need to create a separate database user for your app and use those credentials. In case you're not familiar with mysql, connect to the database as the root user and run these commands:

create user your_username@localhost identified by 'your-password';
grant all privileges on demo.* to your_username@localhost;

Fill in your own values for your_username and your-password, and use them in your .env file for DB_USERNAME and DB_PASSWORD. These commands create a new user and give it full permissions to use the demo database.

Edit. I'm assuming the demo database already exists. If not, it has to be created first.

Please or to participate in this conversation.