-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 none of them solved the issue.
I also tried creating a new mysql user, but it returned another error:

SQLSTATE[HY000] [1698] Access denied

My current env:

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel
DB_USERNAME=user
DB_PASSWORD=password
The Blind Hawk
  • 1,199
  • 8
  • 24
  • 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,285
  • 2
  • 9
  • 14
0

This problem was due to permission issues.
I could not migrate using root because Ubuntu 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';

Putting it all together it would be:

sudo mysql -u root

mysql> USE mysql;
mysql> CREATE USER 'YOUR_SYSTEM_USER'@'localhost' IDENTIFIED BY 'YOUR_PASSWD';
mysql> GRANT ALL PRIVILEGES ON *.* TO 'YOUR_SYSTEM_USER'@'localhost';
mysql> UPDATE user SET plugin='mysql_native_password' WHERE User='YOUR_SYSTEM_USER';
mysql> FLUSH PRIVILEGES;
mysql> exit;

sudo service mysql restart
The Blind Hawk
  • 1,199
  • 8
  • 24
-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
  • 6