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.
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.
@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).
@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.