Home > OS >  cannot migrate in new Laravel project
cannot migrate in new Laravel project

Time:12-22

So, I am trying to create a laravel project from scratch.
I ran the following:

composer global require "laravel/installer=~1.1"
composer create-project laravel/laravel my-project-name
php artisan serve

Now I got the new laravel project ready to go, and tried to run:

php artisan migrate

but it returned an error:

SQLSTATE[HY000] [2002] Connection refused

I looked around other answers to similiar questions, but non of them solved the issue.
I also tried creating a new mysql user, but it returned another error:

SQLSTATE[HY000] [1698] Access denied

Any help would be appreciated!

My current env:

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel
DB_USERNAME=user
DB_PASSWORD=password

I am able to go to 127.0.0.1:8000 after I run php artisan serve but I cannot access 127.0.0.1:3306 which is where I thought phpmyadmin was?
I have yet to change anything, but if there is any other piece of code I should share please lemme know!

CodePudding user response:

  1. Make sure mysql is installed.
  2. Make sure mysql is running.
  3. Make sure you have added a laravel database in mysql, matching your .env
  4. Make sure you have added the user from your .env. It should have access to the database from your .env with the password from your .env

Specific steps to accomplish the first two will vary based on your environment and operating system, but are covered in great detail on stackoverflow and on the web in general.

Creating the database should be a matter of create database laravel; in mysql as the root user.

Adding a user is as simple as `CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'password';

Giving permissions to the database, GRANT ALL PRIVILEGES ON laravel.* TO 'newuser'@'localhost'; FLUSH PRIVILEGES

CodePudding user response:

Please, first check if 3306 port is disoccupied, and check if your firewall are not blocking this port. If it is ok, clean your cache applying php artisan config:clear. If this not solve your problems, is really possible you need reinstall laravel following brombeer's recomendations. I hope helping you

  • Related