-1

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

composer global require "laravel/installer=~1.1" //this code was not necessary
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!

Update
As mentioned by @brombeer the fact that I could not go to 127.0.0.1:3306 was because I did not have phpmyadmin installed.
I just got confused because I had been working on a lot of projects with a docker, and automatically assumed it had been already been installed on this device (docker sets up phpmyadmin automatically I think?)

  • 2
    Unrelated: no need to install the `laravel/installer` when you use `composer create-project ...` to create a project – brombeer Dec 21 '21 at 10:46
  • 1
    "_but I cannot access 127.0.0.1:3306 which is where I thought phpmyadmin was_" You need to install phpMyAdmin yourself first. And your `MySQL` server is running at `127.0.0.1:3306`, _not_ phpMyAdmin – brombeer Dec 21 '21 at 10:48
  • Try running `php artisan config:clear` to clear out any cached values – brombeer Dec 21 '21 at 10:49

3 Answers3

0
  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

James Clark
  • 1,238
  • 2
  • 9
  • 14
0

So, it was a permission error.
I could not migrate using root because it needs sudo now, so I created a new user following the steps in option 2 of the first answer here.

One thing I had to change was that I had to run

UPDATE user SET plugin='mysql_native_password' WHERE User='YOUR_SYSTEM_USER';

instead of

UPDATE user SET plugin='auth_socket' WHERE User='YOUR_SYSTEM_USER';

Also as @brombeer mentioned, I did not have phpmyadmin installed. I could access phpmyadmin on other projects I was working on because they had a docker for it.

-2

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

FGalanB
  • 7
  • 5