Try to checkout the ".env" file in your root directory. This values are taken first. Yours are just the defaults, if there are none given in the .env file.
Laravel 5: php artisan migrate - problem
Hello, I installed Laravel 5 yesterday and having troulbe to do a simple user table migration. My local env is running XAMPP The error is:
exception 'PDOException' with message 'SQLSTATE[HY000] [1045] Access denied for user 'homestead'@'localhost' (using password: YES)'
but my setting in app/config/databese.php:
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', '127.0.0.1'),
'database' => env('DB_DATABASE', 'laravel5_db'),
'username' => env('DB_USERNAME', 'root'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
],
I've search all folders and could find any trace of "homestead". Why it asks for a "homestead"?
Thanks Stefanbauer! That was easy! :)
Hi, I'm totally new to Laravel and have almost the same issue. When I try to login on a fresh install, I get:
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'homestead.users' doesn't exist (SQL: select * from `users` where `email` = ***@gmail.com limit 1)
Then I try to check migrations,but:
$ php artisan migrate:status
exception 'PDOException' with message 'SQLSTATE[HY000] [1045] Access denied for user 'homestead'@'localhost' (using password: YES)' in H:\___DEV___\laravel\laravel-main\vendor\laravel\framework\src\Illuminate\Database\Co
nnectors\Connector.php:47
If I understand correctly, Laravel connects from the page, but not from console? What am I missing? Thanks
@KarmaLack are you running laravel on homestead or via xampp? The issue seems to be with database configuration and all you need is to check if you have a file labeled .env in the root of your laravel 5 installation.
@KarmaLack you seem to be running your migrations on the host machine (or you don't use a VM).
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.
Good luck.
So it seems I missed the part where I connect to ssh :) But it says no migrations:
vagrant@homestead:~/Code/laravel-main$ php artisan migrate:status
No migrations found.
Should I create users table manualy or I still miss something? :)
Not 100% sure what migrate:status does. But if there's migrations in the database/migrations directory they'll get run you run php artisan migrate. Is there anything in database/migrations? There should be 2 by default create_users_table create_password_reset_table these migrations are responsible for creating the tables.
php artisan migrate did the job. By description I understood status should show if there are any migrations to run.
Thanks all for the help.
P.S. After migration, that's what migrate:status output is:
vagrant@homestead:~/Code/laravel-main$ php artisan migrate:status
+------+------------------------------------------------+
| Ran? | Migration |
+------+------------------------------------------------+
| ✔ | 2014_10_12_000000_create_users_table |
| ✔ | 2014_10_12_100000_create_password_resets_table |
+------+------------------------------------------------+
@KarmaLack glad you got things sorted :)
To help other forum users, it would be good if you marked this thread as "Answered" by clicking the "tick" below the post that was most helpful to you.
@sitesense, I think the OP was @Hobet. ;)
@rawfan oops, my bad :)
Found a good solution again here, really nice quick updating tutorials of laravel http://tutsnare.com/access-denied-for-user-homesteadlocalhost-laravel-5/
@markgxr I don't think digging up old threads to post a blatant link to a third party site is good etiquette. @JeffreyWay
changing credentials in env. file solves one problem but in other hand you still get an error if you try to use tinker while running homestead environment.
This is my solution:
.env
#DB_HOST=127.0.0.1:33060
DB_HOST=localhost
DB_DATABASE=lara5
DB_USERNAME=homestead
DB_PASSWORD=secret
When I want to use artisan I "just" uncomment first and comment the second DB_HOST. It's stupid, I know. :D
@sitesense Thanks bud! I sshed into my vm and boom we are good.
I did the same thing that shonetow showed up here and I was able to migrate correctly too.
@markgxr Your link was able to solve my problem. thank you.
I have the same error yet I have set .env i have [PDOException] SQLSTATE[HY000] [1045] Access denied for user 'postgres'@'localhost' (using password: YES)
i postgres database owner=postgres.. some on have any idea ??
I had this same issue with xampp. After editing the .env file I was still getting an error. Then I went to PHPMYADMIN and manually created a database. After trying php artisan migrate again everything worked great!
Well, maybe is to late but... I was struggled an hour trying to understand. I created manually my database in my xampp. I created user and pass for the database, granted all permision, changed .env file, migrate, clear config and nothing happens... Same SQLSTATE[HY000] [1045] Access denied. At the end, It occurred to me, restart php artisan serve and works... xD
i am using homestead , i want some help. I am creating new table with php artisan and after then configure file then. I want to migrate this thing to vagrant ssh but here show :
[Illuminate\Database\QueryException]
SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'users' alre
ady exists (SQL: create table users (id int unsigned not null auto_incr
ement primary key, name varchar(255) not null, email varchar(255) not n
ull, password varchar(255) not null, remember_token varchar(100) null,
created_at timestamp null, updated_at timestamp null) default character
set utf8 collate utf8_unicode_ci)
[PDOException] SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'users' alre ady exists
Yes, commenting out the mysql server setting in /.env file helps. You need to correct settings in /config/database.php.
HOWEVER /.env file is HIDDEN. You can access it but you cannot see it in the directory. It would be much easier if I knew that on time ;)
I am new to this. I did not install Homestead and it is not in my .env file, yet when I try "php artisan migrate", I get the error "Access denied for user 'homestead '@'localhost' ".
If you are on Mac, you should change your port from 3306 to 8889. Your Mac has both SQL's running which cause this problem.
Here in 2018 :) and noticing that there are a few similar but not entirely the same issues that are raised in this thread.
For those that arrive here troubleshooting a No migrations found to your php artisan migrate:status query, please remember to first run php artisan migrate:install. This presumes your database connection is properly configured – which roughly comprises the other remarks in this thread – and which will vary depending on your setup (homestead, valet, xampp, custom/else, etc).
Keep calm and Laravel on!
Thanks a lot @ Stefanbauer. Your answer really helped
Illuminate\Database\QueryException : SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client (SQL: select * from information_schema.tables where table_schema = own and table_name = migrations and table_type = 'BASE TABLE')
at /Users/guntimanideep/.bitnami/stackman/machines/xampp/volumes/root/htdocs/own/blog/vendor/laravel/framework/src/Illuminate/Database/Connection.php:665 661| // If an exception occurs when attempting to run a query, we'll format the error 662| // message to include the bindings with SQL, which will make this exception a 663| // lot more helpful to the developer instead of just the database's errors. 664| catch (Exception $e) {
665| throw new QueryException( 666| $query, $this->prepareBindings($bindings), $e 667| ); 668| } 669|
Exception trace:
1 PDOException::("PDO::__construct(): The server requested authentication method unknown to the client [caching_sha2_password]") /Users/guntimanideep/.bitnami/stackman/machines/xampp/volumes/root/htdocs/own/blog/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:70
2 PDO::__construct("mysql:host=127.0.0.1;port=3306;dbname=own", "root", "", []) /Users/guntimanideep/.bitnami/stackman/machines/xampp/volumes/root/htdocs/own/blog/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:70
CAN ANY ONE HELP ME TO FIX THESE ERROR
Please use the argument -v to see more details.
I'm pretty sure that is the issue related to Laravel not supporting the new secure MySQL authentication method. You gotta change it to "standard" or "legacy". See https://stackoverflow.com/questions/49931541/mysql-changing-authentication-type-from-standard-to-caching-sha2-password. @mandyziya143
Please or to participate in this conversation.