Laravel SQLSTATE[HY000] [2002] Connection refused - php

so I want to deploy my existing Laravel project into my digital ocean VPS
I used this tutorial and I uploaded my site successfully.
My .env file is:
APP_ENV=local
APP_KEY=my app key
APP_DEBUG=true
APP_LOG_LEVEL=debug
APP_URL=http://localhost
DB_CONNECTION=mysql
DB_HOST=my ip
DB_PORT=3306
DB_DATABASE=form
DB_USERNAME=root
DB_PASSWORD=my pass
But here is the problem: I used MySQL and created and ran
php artisan migrate
and got these errors:
[Illuminate\Database\QueryException] SQLSTATE[HY000] [2002] Connection refused (SQL: select * from information_schema.tables where table_schema = form and table_name = migrations)
and
[PDOException] SQLSTATE[HY000] [2002] Connection refused

In your .env file, change DB_HOST from 127.0.0.1 to localhost

Put string:
DB_SOCKET=/Applications/MAMP/tmp/mysql/mysql.sock
after DB_PASSWORD=
It works for MAMP. Set your path to mysql.sock

In your .env file, change DB_HOST from 127.0.0.1 to localhost
and then
php artisan cache:clear
php artisan route:clear
php artisan config:clear
php artisan view:clear
This worked for me.

There are a few possibilities why your getting this error.
database server isn't started, check if you can still use your phpmyadmin. If you can still use it then nothing is wrong with your database server.
wrong config; check username, password and server settings in both your .env file and your config/database.php
no privileges to the server and or database with given credentials
Looking at the steps you already took I think it's the last.
Check to see if this user has access to the database from the remote location. By default the root user has access to the server locally (localhost,127.0.0.1 and ::1).
So check to see if the user has access from either your remote ip or from anywhere.
As you are using digitalocean I would suggest to check if they have a specific configuration to connect to mysql database.

SELinux might be the cause.
Set this rule and try again:
sudo setsebool -P httpd_can_network_connect_db=1

After long hours this worked for me:
Changing the port in php My Admin previously 8889
APP_NAME=laravel
APP_ENV=local
APP_KEY= YOUR KEY
APP_DEBUG=true
APP_URL=127.0.0.1
LOG_CHANNEL=stack
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_SOCKET=/Applications/MAMP/tmp/mysql/mysql.sock
and then
php artisan cache:clear
php artisan route:clear
php artisan config:clear
php artisan view:clear

Before you do changes as per instructed above,
check if your database server running or not. If you are using command prompt, running mysql.server status or mysqld status shall show the database status.
If the database is running, check if the dbuser is allow to connect from '%' or 'localhost' or '127.0.0.1'. If not, just grant the user access from '%'
If you have done 1 and 2 and still can't connect, see if the db user is allow to access the schema. If not, grant access to the schema
If you reach here and still got the same error, try to restart you web server.

My composer was installed globally, i run php artisan serve without starting xampp & getting this error. After running my xampp server, it's working fine from my side.

In attempt to provide a solution for those of you that have not found success in any of the already mentioned answers, I will share my solution.
Coming from Windows 10 I was of the understanding that the password for the root user was always blank thus my .env file looked as follows:
DB_USERNAME=root
DB_PASSWORD=
On Mac, the password is defaulted to "root" also. Changing my .env file to look as follows fixed my issue:
DB_USERNAME=root
DB_PASSWORD=root

in your .env file
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=ur_db_name
DB_USERNAME=ur_db_username
DB_PASSWORD=ur_dbuser_password

If you are using XAMPP on Mac, just use the embedded IP Address from your XAMPP Dashboard as DB_HOST instead of 127.0.0.1 or localhost.
If It still refuses to connect deal with a user but stick on that idea.

Related

SQLSTATE[HY000] [1045] Access denied for user 'root'#'localhost' (using password: NO) -> Laravel 8

I'm taking a course of Laravel, and I'm with some problems during the Databases Module...
It's about "php artisan migrate", when I try to do this command, appears me this message: After do the command
That's my .env
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=blog
DB_USERNAME=root
DB_PASSWORD=
(I've already try put password at .env, but still the same)
(#Suleman and #John Lobo, can you make an answer so that I can rate it as correct?!)
It's just php artisan config:cache after some changes at .env and database.php (like #John Lobo said)
The error message is telling you the issue - that the user 'root' doesn't have access to the database without a password being specified.
Do you know your root password?
Has one been set?
If you know your password add it to your .env file.
If one hasn't been set read the manual for mysql/mariadb on your operating system for how to set the root password - then add it to the .env file.

Migration through php artisan results in an QueryException

I have read a lot of posts regarding artisan migration issues, but unfortunately none of them are applicable to my situation.
So I am running Laravel Homestead via Vagrant and I have created a new database in the Vagrant VM.
On my Ubuntu desktop I can connect to the database via DBeaver and it shows the database. Because I am running the database in a Vagrant VM, I am connected to it through 192.168.10.10 (specified in the Homestead.yaml file) and not localhost (127.0.0.1). So far so good.
I created a migration file by running the following command: php artisan make:migration create_todo_table. However, when I run php artisan migrate I get the following exception error:
Illuminate\Database\QueryException
Could not find driver (SQL: select * from information_schema.tables where table_schema = homestead and table_name = migrations and table_type = 'BASE TABLE')
The data regarding the database in my .env file is as follows:
DB_CONNECTION=mysql
DB_HOST=192.168.10.10
DB_PORT=3306
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret
I have tried clearing the cache by running php artisan config:cache but had no luck.
Can someone give me some insight, please?
DB host inside your vagrant should be localhost or 127.0.0.1 because project and database both are inside vagrant but DBeaver is outside vm so 192.168.10.10 is okay for DBeaver.
DB_HOST=localhost
I got in fixed by editing my php.ini file.
For Windows I changed ;extension=php_pdo_mysql to extension=php_pdo_mysql.dll.
For Ubuntu I changed it into extension=pdo_mysql.so.
After that, I still got an error stating that the connection was actively refused. I fixed this by changing DB_HOST=localhost to DB_HOST=192.168.10.10.
Hope this will help someone someday!

SQLSTATE[HY000] [1045] Access denied for user 'root'#'localhost' (using password: NO) . DB_HOST set to localhost

I moved the Laravel project from localhost to server. Which I have done every step on the server.
I am able to view the login page on my server. The problem is I am not able to connect with my MySQL server.
My .env file:
APP_NAME=Transport
APP_ENV=local
APP_KEY=base64:mrakeyidharhaikonsdf
APP_DEBUG=true
APP_URL=http://localhost
LOG_CHANNEL=stack
DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=transport_db
DB_USERNAME=root
DB_PASSWORD=mypass
I tried to change the host to 127.0.0.1 and also tried to put my server's IP address. It didn't helped me. Am I missing something?
My error:
SQLSTATE[HY000] [1045] Access denied for user 'root'#'localhost' (using password: NO) (SQL: select count(*) as aggregate from users where email = user.email#gmail.com)
I know this question may have answers already on Stack Overflow. But I have different issue here.
To be honest, while working on Laravel 6, I also faced this issue many times and probably was unable to figure out the solution. I tried commands like
php artisan config:cache and php artisan config:clear, but these two commands didn't help.
To come over this issue, you have to execute all the below commands:
php artisan route:cache
php artisan route:clear
php artisan config:cache
php artisan config:clear
php artisan optimize
Note: Make sure in .env you have add db_password and it is not null and also check if your db_password uses any special character. Always enclose them in "".
Example:
DB_PASSWORD="%123456%"
To debug this issue you can also create a test route and then dump the .env variable there to check if they have the correct values or not.
Route::get('/test/env', function () {
dd(env('DB_DATABASE')); // Dump 'db' variable value one by one
});
Note: Please make sure to restart your server.
Make sure your database credentials and database host are set correctly:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE="your_database_name"
DB_USERNAME="put_db_user_name _here"
DB_PASSWORD="put_db_password_here_if_have_set"
If you have not set any database password then add:
DB_PASSWORD=""
The problem is that the project made a cache file. 'config.php' must be deleted in order to allow the system to restart and you can do so by locate this file and deleting it:
bootstrap/cache/config.php
I was working in the Laravel framework using homestead and had such a problem. In fact, this error was because I did not create the database in Vagrant. So, I created the database. In more details:
run vagrant ssh to get homestead command line.
run mysql to start the MySQL command line client.
run create database database_name; to create your database. Note that the database should be inside two ` (not ') marks.
Modify the .env file of the Laravel project as below:
DB_CONNECTION=mysql
DB_HOST=192.168.10.10
DB_PORT=3306
DB_DATABASE=askidb2
DB_USERNAME=homestead
DB_PASSWORD=secret
(if you previously made your model and configured files in Laravel projects for creation tables), run php artisan migrate in the command line of the project's folder. This causes it to create tables in the askidb2 database.
(perhaps optional for you) since before I set needed files for seeding the question table I just run php artisan db:seed to seed my desired table(s).
If you use Homestead to serve your application, you must connect to the Homestead built-in database. Otherwise, I get an error (SQLSTATE[HY000] [1045] Access denied for user 'root'#'localhost') when I try to connect to the MySQL database that is installed on my Mac.
Here is how I connect to the Homestead database. I am not sure why the host → 127.0.0.1 from the Laravel documentation doesn't work.
In the .env file
DB_CONNECTION=mysql
DB_HOST=192.168.10.10
DB_PORT=3306
DB_DATABASE=blog
DB_USERNAME=homestead
DB_PASSWORD=secret
I use Sequel Pro as the GUI to manage the database, and here is how I connect Sequel Pro to the Homestead MySQL database.
Connect with standard mode
Host: 192.168.10.10
User: homestead
Password: secret
Port: 3306
Connect with SSH mode
So the problem is mine. I apologize for that.
I missed to put my DB_PASSWROD inside "". So that caused my two hours.
I have the password which contains some special characters at the beginning. So it should be inside the "" to avoid the problems.
For example, if my password is "%helloworld#",
then in the .env file, it should be:
`DB_PASSWORD="%helloworld#" `
Previously, I had
`DB_PASSWORD=%helloworld#
I had this error while my connection with the database was established. The problem was that I was on localhost, not 127.0.0.1.
First
DB_DATABASE="your_database_name"
DB_USERNAME="put_db_user_name _here"
DB_PASSWORD="put_db_password_here_if_have_set"
Then type
php artisan config:clear
This will make your problem clear. Then type
php artisan migrate
I had this error because my XAMPP user Account access for root and password did not match Laravel .env database DB_USERNAME & DB_PASSWORD.
This will Work:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE="your_database_name"
DB_USERNAME="put_db_user_name _here"
DB_PASSWORD="put_db_password_here_if_have_set"
This may also be due to the DB_PORT. Go to the PhpMyAdmin Database server and check the server.
So I changed from this
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
to
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3307
Change the .env as follows
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE="Your DB name"
DB_USERNAME=root
DB_PASSWORD=
and then run php artisan config:cache
and then run php artisan migrate:fresh --seed
and then run php artisan serve
Please make sure to have the same db name in .env file and db name in php myadmin
Kindly check your mysql port no as well.
If you have changed your xampp mysql port, then do check PORT Number in your projectfolder ".env" file as well as "database.php" file.
In my case, if I have Bitnami WordPress. It's a service using an Apache/localhost address, so my XAMPP instance is only accessible via 127.0.0.1 and when accessing localhost I got 'Access denied error ...'. Then when I stop the Bitnami service, everything is back to normal.

Laravel 5.5 SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: No such host is known

After installing Laravel 5.5 for a new project, I get this error:
[Illuminate\Database\QueryException]
SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: No such host is known.
.env db connection info:
DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=lavavelproject
DB_USERNAME=root
DB_PASSWORD=
Dev environment: Windows
PHP 7.0
Try to clear cache by terminal:
php artisan config:cache
Do it always when you change config file.
Sometimes the most common issue is using localhost, change this to 127.0.0.1 and it should work for you.
Sometimes you will have to run:
php artisan cache:clear and in the rare moments as I have found also running php artisan key:generate
Faced the same issue, changing DB_HOST=mysql to DB_HOST=localhost solved my problem.
I had same problem. The solution was to change  DB_HOST=mariadb   to   DB_HOST=localhost.
If it matters, my localhost is 127.0.0.1.
Anyway, for my project and my PC config, the problem comes from Apache (XAMP), I think.
My project run in Docker containers.
I put in my ".env" file above two lines,
DB_HOST=mariadb
#DB_HOST=localhost.
The last line (localhost) is commented and not change when I run the project.
For running php artisan commands, I'll deactivate "mariadb" and activate "localhost".
Simple trick to not change much.
On your application .env should be pointing to the IP of your database. Your database is the same server as your Laravel application, it should be:
.env
DB_HOST=127.0.0.1

Access denied for user 'homestead'#'localhost' (using password: YES)

I'm on a Mac OS Yosemite using Laravel 5.0.
While in my local environment, I run php artisan migrate I keep getting :
Access denied for user 'homestead'#'localhost' (using password: YES)
Configuration
Here is my .env
APP_ENV=local
APP_DEBUG=true
APP_KEY=*****
DB_HOST=localhost
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret
app\config\database.php
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
'database' => env('DB_DATABASE', 'homestead'),
'username' => env('DB_USERNAME', 'homestead'),
'password' => env('DB_PASSWORD', 'secret'),
'unix_socket' => '/tmp/mysql.sock',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
]
How do I avoid this kind of error ?
I've tried :
1
in app/database.php
Replace localhost with 127.0.0.1
'host'=> env('DB_HOST', 'localhost') -->'host' => env('DB_HOST', '127.0.0.1')
Also, in .env
DB_HOST=localhost --> DB_HOST=127.0.0.1
2
Try specify environment
php artisan migrate --env=local
3
Check to see if the MySQL is running by run
mysqladmin -u homestead -p status Enter password: secret
I got
Uptime: 21281 Threads: 3 Questions: 274 Slow queries: 0 Opens: 327 Flush tables: 1 Open tables: 80 Queries per second avg: 0.012
Which mean it's running.
4
Check MySQL UNIX Socket (This step work for me)
The reason of Access denied for user ‘homestead’#’localhost’ laravel 5 error is caching-issue of the .env.php file cause Laravel 5 is using environment based configuration in your .env file.
1. Go to your application root directory and open .env file (In ubuntu may be it’s hidden so press ctrl+h to show hidden files & if you are in terminal then type : ls -a to show hidden files) in your editor and change database configuration setting. then save your .env file
DB_HOST=localhost
DB_DATABASE=laravelu
DB_USERNAME=root
DB_PASSWORD=''
2. then restart your apache server/web server. and refresh your page and you have done
3. If still issue try to run below command to clear the old configuration cache file.
php artisan config:clear
Now you are done with the error
TLDR: You need to stop the server Ctrl + c and start again using php artisan serve
Details:
If you are using Laravel, and have started local dev server already by php artisan serve
And after having above server already running, you change your database server related stuff in .env file. Like moving from MySQL to SQLite or something. You need to make sure that you stop above process i.e. Ctrcl C or anything which stop the process. And then restart Artisan Serve again i.e. y php artisan serve and refresh your browser and your issue related to database will be fixed. This is what worked for me for Laravel 5.3
Two way to solve it
First way (Not recommended)
Open your database config file (laravel_root/config/database.php) & search for the below code block.
'host' => env('DB_HOST', 'localhost'),
'database' => env('DB_DATABASE', 'blog'),
'username' => env('DB_USERNAME', 'root'),
'password' => env('DB_PASSWORD', ''),
Change the code block as below
'host' => 'yourHostName',
'database' => 'YourDatabastName',
'username' => 'YoutDatabaseUsername',
'password' => 'YourDatabasePassword',
Second way (Recommended by Laravel)
Check your Laravel root there have a file call .env if not exist, look for .env.example, copy/rename it as .env after that the file looks blow !
APP_ENV=local
APP_DEBUG=true
APP_KEY=someRandomNumber
DB_HOST=localhost
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync
MAIL_DRIVER=smtp
MAIL_HOST=mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
Modify the below block as follow
DB_HOST=yourHostName
DB_DATABASE=yourDatabaseName
DB_USERNAME=yourDatabaseUsername
DB_PASSWORD=youPassword
Now it will work fine.
if you are using php artisan migrate NOT from vagrant box but from host machine then you must define inside the .env the ip of the box 192.168.10.10
and obviously set permission to homestead user from your ip
something like
grant all privileges on *.* to 'homestead'#% identified by 'secret';
in .env file
DB_HOST=192.168.10.10
DB_DATABASE=homestead
DB_USERNAME=homestead
If you are using the PHP's default web server (e.g. php artisan serve) you need to restart your server after changing your .env file values.
I had the same issue and in the end It turned out that I just had to restart the server and start again
Ctrl + c then
php artisan serve
When you install Homestead, this creates a default "homestead"
database in the VM. You should SSH into the VM homestead ssh and run
your migrations from there. If you are working locally with no VM,
you'll need to create your database manually. By default, the database
should be called homestead, the username is homestead and the password
is secret.
check this thread on laracasts or this blog post for more details
if you are getting
[PDOException] SQLSTATE[HY000] [2002] No such file or directory
try changing "host" in the /app/config/database.php file from "localhost" to "127.0.0.1" . you can find more details and other fixes here on this thread.
Also check whether you have specified the correct unix_socket . check this thread .
Check MySQL UNIX Socket
Find unix_socket location using MySQL
mysql -u homestead -p
mysql> show variables like '%sock%';
+-----------------------------------------+-----------------------------+
| Variable_name | Value |
+-----------------------------------------+-----------------------------+
| performance_schema_max_socket_classes | 10 |
| performance_schema_max_socket_instances | 322 |
| socket | /var/run/mysqld/mysqld.sock |
+-----------------------------------------+-----------------------------+
3 rows in set (0.00 sec)
Then I go to config/database.php
I update this line : 'unix_socket' => '/tmp/mysql.sock',
to : 'unix_socket' => '/var/run/mysqld/mysqld.sock',
That's it. It works for my as my 4th try.I hope these steps help someone. :D
In Windows PC Follow below.
Access the Root folder of your application.
Edit the .env file
Edit the Highlighted and change the UserName and the password adn The database Name accordingly.
in my case,
after restarting my server the problem was gone.
exit/close the "php artisan serve" command and
re-run the command "php artisan serve" command.
in my case (laravel 5+) i had to wrap my password in single quotation marks and clear config cache:
DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=database_name
DB_USERNAME=user_name
DB_PASSWORD='password'
and then run:
php artisan config:clear
Sometime in the future. Try to clear your config first
php artisan config:clear.
Close all the terminal /cmd windows and then restart terminal/CMD and this should get rid of the error message. See if it works.
after config db restart the:
php artisan serve
If the serve is active before set db config.
i using laravel 5.* i figure i have a file call .env in the root of the project that look something like this:
APP_ENV=local
APP_DEBUG=true
APP_KEY=SomeRandomString
DB_HOST=localhost
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync
MAIL_DRIVER=smtp
MAIL_HOST=mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
And that was over writing the bd configuration so you can wheather deleted those config vars so laravel take the configuration under /config or set up your configuration here.
I did the second and it works for me :)
Got it! Log in as root and grant homestead#localhost the rights to everything.
From your terminal:
$ homestead ssh
$ mysql -u root -p
Enter password: secret
mysql> grant all privileges on *.* to 'homestead'#'localhost' identified by 'secret';
Query OK, 0 rows affected (0.00 sec)
exit
Now homesteads regular user has access to all of your tables, and as such, should be able to run things like migrations.
After change .env with the new configuration, you have to stop the server and run it again (php artisan serve). Cause laravel gets the environment when it's initialized the server. If you don't restart, you will change the .env asking yourself why the changes aren't taking place!!
All you have to do is alter your .env file.
DB_HOST=localhost
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret
In front of DB_DATABASE, write the name of the database and in front of DB_USERNAME, use root.
I just wanted to post this because this issue frustrated me for about 3 hours today. I have not tried any of the methods listed in the other answers, though they all seem reasonable. In fact, I was just about to try going through each of the above proposed solutions, but somehow I got this stroke of inspiration. Here is what worked for me to get me back working -- YMMV:
1) Find your .env file.
2) Rename your .env file to something else. Laravel 5 must be using this file as an override for settings somewhere else in the framework. I renamed mine to .env.old
3) You may need to restart your web server, but I did not have to.
Good luck!
You have to run the $ php artisan migrate command from within Homestead, not your Mac.
Check your ".env" file in the root folder. is it correct?
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret
i have find solution
Go to your application root directory and open .env file (In ubuntu may be it’s hidden so press ctrl+h to show hidden files) in your editor and change database configuration setting. then save your .env file
then restart your apache server/web server. and refresh your page and you have done
If still issue try to run below command to clear the old configuration cache file.
This worked for me gl ...
just change these things in the .env file of your root folder.
DB_DATABASE=your_db_name
DB_USERNAME=your_db_user_name
DB_PASSWORD='your_db_password'
It worked for me.
Log into MYSQL - use the mysql database.
Select * from User;
Make sure that your HOST column is correct. It should be the host that you are connecting from (your application server) be it IP address, or DNS name. Also '%' will work (meaning wildcard) but will not be secure.
Check your .env file, if you have edited any of the variables, kindly restart laravel server, and your problem will be solved
A. After updating the .env file with database settings, clear laravel setting by "running php artisan config:clear"
B. Please make sure you restart your apache server / rerun the "php artisan serve" command for your settings to take effect.
I had the same issue using SQLite. My problem was that DB_DATABASE was pointing to the wrong file location.
Create the sqlite file with the touch command and output the file path using php artisan tinker.
$ touch database/database.sqlite
$ php artisan tinker
Psy Shell v0.8.0 (PHP 5.6.27 — cli) by Justin Hileman
>>> database_path(‘database.sqlite’)
=> "/Users/connorleech/Projects/laravel-5-rest-api/database/database.sqlite"
Then output that exact path to the DB_DATABASE variable.
DB_CONNECTION=sqlite
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=/Users/connorleech/Projects/laravel-5-rest-api/database/database.sqlite
DB_USERNAME=homestead
DB_PASSWORD=secret
Without the correct path you will get the access denied error
If you have an error returning something like PDOException in Connector.php line 55: SQLSTATE[HY000] [1049] Unknown database 'laravelu' is due to you are changing your batabase config as DB_DATABASE=laravelu. So for now you either:
Change the DB_DATABASE=[yourdatabase] or
create a database called laravelu in your phpmyadmin
this should be able to solve it
In my case the error was "caused" by my Homestead / Vagrant configuration about which I forgot :) trying to run the migration just from command line.
In case of using Homestead Vagrant Box environment you should run your migration from within your Homestead machine (after connecting to it using ssh: vagrant#192.168.10.10:22) then the access rights will be OK and will allow the migration to run.
From your question, it seems you are running homestead. In that case, make sure you're running the commands in your VM. Many devs including me often make mistake and run artisan commands outside of VM which the commands will try to connect to our local database accessible through localhost which is different from the database used by homestead. Cd to your Homestead directory and run
vagrant ssh
then cd into code if that is where you keep your projects and cd into your project and run php artisan migrate again
I hope this will help other people.
My app had been set up to use .env.local. I was checking .env the whole time.
Check that you are editing the correct .env file if you have several.

Categories