简体   繁体   中英

php artisan migrate can not find my database

I've created MySQL database named resume_manager My DB username is root and password is password But when I run php artisan migrate The error message bellow is showing.

 Illuminate\Database\QueryException  : SQLSTATE[HY000] [1049] Unknown database 'resume_manager' (SQL: select * from information_schema.tables where table_schema = resume_manager and table_name = migrations)

  at /home/geralt/Music/resume-manager/vendor/laravel/framework/src/Illuminate/Database/Connection.php:664
    660|         // If an exception occurs when attempting to run a query, we'll format the error
    661|         // message to include the bindings with SQL, which will make this exception a
    662|         // lot more helpful to the developer instead of just the database's errors.
    663|         catch (Exception $e) {
  > 664|             throw new QueryException(
    665|                 $query, $this->prepareBindings($bindings), $e
    666|             );
    667|         }
    668| 

  Exception trace:

  1   PDOException::("SQLSTATE[HY000] [1049] Unknown database 'resume_manager'")
      /home/geralt/Music/resume-manager/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:68

  2   PDO::__construct("mysql:host=127.0.0.1;port=3306;dbname=resume_manager", "root", "password", [])
      /home/geralt/Music/resume-manager/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:68

  Please use the argument -v to see more details.

I'm running MySQL on Xampp. I've checked my.cnf file port is set to the default 3306 I don't know what's going on. By the way I'm using Linux Mint . And I also ran all the commands regarding cache

          php artisan cache:clear
          php artisan route:cache
          php artisan config:clear
          php artisan view:clear

This is my .env file setup:

APP_NAME=Laravel
APP_ENV=local
APP_KEY=
APP_DEBUG=true
APP_URL=http://localhost

LOG_CHANNEL=stack

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=resume_manager
DB_USERNAME=root
DB_PASSWORD=password

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

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null

PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_APP_CLUSTER=mt1

MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"

From the error it is sure that there is no problem with you port, username and password they all are correct... so just double check resume_manager exist or not else;

simple go to your mysql console and create an empty database

mysql> CREATE DATABASE resume_manager;

or

you do the same using phpmyadmin too...

if database already exist it will give error else new required db will be created... (there might be some typo issue in your old db name)

尝试新建数据库,如果同样的问题再次发生,你可以使用这个命令

php artisan config:cache

Whenever we change the DB_DATABASE , DB_USERNAME and DB_PASSWORD in .env file, we need to clear the cache: php artisan config:cache

After you can run the migrate Artisan command: php artisan migrate

更改.env文件后始终清除配置

php artisan config:cache

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM