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

LSM's avatar
Level 8

php artisan migrate gives sql error

In terminal, when I try to migrate using php artisan migrate, I get this sql error:

   Illuminate\Database\QueryException 

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

  at vendor/laravel/framework/src/Illuminate/Database/Connection.php:678
    674▕         // If an exception occurs when attempting to run a query, we'll format the error
    675▕         // message to include the bindings with SQL, which will make this exception a
    676▕         // lot more helpful to the developer instead of just the database's errors.
    677▕         catch (Exception $e) {
  ➜ 678▕             throw new QueryException(
    679▕                 $query, $this->prepareBindings($bindings), $e
    680▕             );
    681▕         }
    682▕ 

      +33 vendor frames 
  34  artisan:37
      Illuminate\Foundation\Console\Kernel::handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))

I believe that I've setup my .env file correctly

APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:6UahK+RBOJO1i6+36UkcUNK3zdcQOnIXlEJv/HpKL9w=
APP_DEBUG=true
APP_URL=http://myproject.test

LOG_CHANNEL=stack
LOG_LEVEL=debug

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

BROADCAST_DRIVER=log
CACHE_DRIVER=file
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_LIFETIME=120

I've tried most of the solutions online including creating a new user with a set password and giving them the same privileges as root but still stuck here. Anyone who has had this issue, how do I fix?

0 likes
9 replies
Sinnbeck's avatar

How are you running your database? Also it seems your config might be cached

php artisan config:clear
LSM's avatar
Level 8

Just ran php artisan config:clear. and got Configuration cache clear! But got the same error.

└─(01:32:48)──> php artisan config:clear                    1 ↵ ──(Fri,Dec18)─┘
Configuration cache cleared!
┌─(~/jgdev/myproject)───────────────────────────────────────(jgreen@JHG:s000)─┐
└─(01:34:15)──> php artisan migrate                             ──(Fri,Dec18)─┘

   Illuminate\Database\QueryException 

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

  at vendor/laravel/framework/src/Illuminate/Database/Connection.php:678
    674▕         // If an exception occurs when attempting to run a query, we'll format the error
    675▕         // message to include the bindings with SQL, which will make this exception a
    676▕         // lot more helpful to the developer instead of just the database's errors.
    677▕         catch (Exception $e) {
  ➜ 678▕             throw new QueryException(
    679▕                 $query, $this->prepareBindings($bindings), $e
    680▕             );
    681▕         }
    682▕ 

      +33 vendor frames 
  34  artisan:37
      Illuminate\Foundation\Console\Kernel::handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))

Hope I'm answering correctly, I have mariadb running on my local machine.

Sinnbeck's avatar
Sinnbeck
Best Answer
Level 102

Ok. Do you still have the user you created? Try with that again, and post the new error if one comes

LSM's avatar
Level 8

wow, seems like that fixed it! All tables successfully migrated. The tables I created aren't in here, but I'm guessing that's because they weren't made on this user.

┌─(~/jgdev/myproject)───────────────────────────────────────(jgreen@JHG:s000)─┐
└─(01:34:20)──> php artisan migrate                         1 ↵ ──(Fri,Dec18)─┘
Migration table created successfully.
Migrating: 2014_10_12_000000_create_users_table
Migrated:  2014_10_12_000000_create_users_table (104.99ms)
Migrating: 2014_10_12_100000_create_password_resets_table
Migrated:  2014_10_12_100000_create_password_resets_table (52.48ms)
Migrating: 2019_08_19_000000_create_failed_jobs_table
Migrated:  2019_08_19_000000_create_failed_jobs_table (62.80ms)
┌─(~/jgdev/myproject)───────────────────────────────────────(jgreen@JHG:s000)─┐
LSM's avatar
Level 8

*Update

Last night when I changed my DB in .env to my created user and ran php artisan migration, I was able to migrate successfully. Even though those weren't the DBs I created.

This morning I tried mysql with the new user and password I created, making sure it matched my .env db. I tried to make a new database to test it out and then migrate. I got the message 'Nothing to migrate'

┌─(~/jgdev/myproject)───────────────────────────────────────(jgreen@JHG:s000)─┐
└─(02:15:15)──> mysql -uadmin  -ppassword                      ──(Fri,Dec18)─┘
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 24
Server version: 10.5.8-MariaDB Homebrew

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> create database sadie;
Query OK, 1 row affected (0.003 sec)

MariaDB [(none)]> \q
Bye
┌─(~/jgdev/myproject)──────────────────────────────────────(jgreen@JHG:s000)─┐
└─(10:23:07)──> php artisan migrate                            ──(Fri,Dec18)─┘
Nothing to migrate.

Then I tried using mysql with user root and creating the same database and got the message that the database already exists.

└─(10:23:15)──> sudo mysql -u root -p                          ──(Fri,Dec18)─┘
Password:
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 26
Server version: 10.5.8-MariaDB Homebrew

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> create database sadie;
ERROR 1007 (HY000): Can't create database 'sadie'; database exists
MariaDB [(none)]> php artisan migrate
    -> \q
Bye
┌─(~/jgdev/myproject)──────────────────────────────────────(jgreen@JHG:s000)─┐
└─(10:25:35)──> php artisan migrate                            ──(Fri,Dec18)─┘
Nothing to migrate.

I can use sql with my root by using sudo, but if I try to enter in as my created user I get this:

┌─(~/jgdev/myproject)──────────────────────────────────────(jgreen@JHG:s000)─┐
└─(10:27:07)──> mysql -u admin -p password                 1 ↵ ──(Fri,Dec18)─┘
Enter password: 
ERROR 1045 (28000): Access denied for user 'admin'@'localhost' (using password: YES)

I can see my created databases in sql pro, but they're all empty except for the one that's the title of my project. Do I need to have rows or something in my DBs for them to properly migrate and show up in my project migration folder?

bilalkh17's avatar

I am also having migrating db using docker compose with nginx server

bilalkh17's avatar

.env

APP_NAME=Laravel APP_ENV=local APP_KEY=base64:4goksxEUeW+BH8NmkB5mD/ByLUaISjsnjQxvK9CyngA= APP_DEBUG=true APP_URL=http://localhost

LOG_CHANNEL=stack LOG_LEVEL=debug

DB_CONNECTION=mysql DB_HOST=db DB_PORT=3306 DB_DATABASE=laravel_db DB_USERNAME=user DB_PASSWORD=password

bilalkh17's avatar

docker-compose exec app php artisan migrate:install

Illuminate\Database\QueryException

SQLSTATE[HY000] [1049] Unknown database 'laravel_db' (SQL: create table migrations (id int unsigned not null auto_increment primary key, migration varchar(255) not null, batch int not null) default character set utf8mb4 collate 'utf8mb4_unicode_ci')

Please or to participate in this conversation.