How can I fix this error? I searched for several forums, but I could not solve it! SQLSTATE [HY000] [1045] Access denied for user 'user' # 'localhost' (using SQL: select * from table where column = number)
A database consists of tables. You will populate the tables of the database using
php artisan migrate --seed
However, you need to create a database first, and use the database name for DB_DATABASE. Creating the database is independent of Laravel. See https://medium.com/#connorleech/build-an-online-forum-with-laravel-initial-setup-and-seeding-part-1-a53138d1fffc for some information on creating a database.
Make sure your .env file has the correct database parameters. e.g.:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=name_of_database
DB_USERNAME=username
DB_PASSWORD=password
Related
I created my first App, using Laravel in the Backend. Everything was running on my localhost and I deployed everything to my Netcup Webhosting Server.
I run composer install successfully, generated the API key by using php artisan key:generate --ansi and set up my .env file. The File looks like:
APP_NAME="App Name"
APP_ENV=prod
APP_KEY=base64_key
APP_DEBUG=false
APP_URL=https://xx.xxxxx.de
LOG_CHANNEL=stack
LOG_DEPRECATIONS_CHANNEL=null
LOG_LEVEL=debug
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=db_name
DB_USERNAME="db_user"
DB_PASSWORD="db_user_password"
The I want to create all the database tables by using php artisan migrate. I tripple checked the values set in the .env and red a lot of solutions of other posts, but nothing worked. I keep getting the following error:
I already added quotes to DB_User and Pasword in .env file. I restarted the server several times and cleaned the cache.
It looks like some problems with auth on the Netcup Web hosting Server. Can you check list of user with access to db_name? Besides, by screenshoot I guessing that hosting add prefix ("k177581_") for db_name and db_user
Solved the issue:
As #N69S correctly suggested it was related to Netcup. For any other Netcup user the following solution.
Netcup devides its Webhosting and Database. Therefore you need to put you Database IP into your .env file. That can be found in the connection data.
I just cloned a website project on GitHub. When I want to migrate, an error like this appears. I have filled in DB_DATABASE and DB_USERNAME many times but it has no effect
.env
APP_NAME="Simple Company Profile"
APP_ENV=local
APP_KEY=base64:HLQuGR0tT28YYt4eg/GPPQpW4L+mii71zIx65nFNxDE=
APP_DEBUG=true
APP_URL=http://localhost
LOG_CHANNEL=stack
DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=cms_pasti
DB_USERNAME=
DB_PASSWORD=
there is also a simple console here to create an admin account, but that also doesn't work
I don't think that cloning a project will automatically replicate the database. You have to create it with a script/sql. Which should be part of the Github project.
So,
Either find the schema and create the database and tables manually.
Or find a sql backup and restore it
You have just cloned the repository but, that doesn´t mean that is ready to run. You have to create a database and connect with it.
Use PHPMyAdmin or any other Database management solution (HeidiSQL, MySQL WorkBench) in order to check if your Database credentials are working.
Another thing that is probably happening is that you have to create the database 'cms_pasti' first and then fill the .env:
DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=cms_pasti
DB_USERNAME=
DB_PASSWORD=
With the proper settings.
When done, you have to run in your console:
PHP artisan migrate
This command will do the migrations to build the database structure. But you have to be sure that the database is already created.
I installed Laravel Passport and migrated the new tables just fine in my database. But when I try to run migrations for the testing database, ie. artisan migrate --database=testing I get:
SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'oauth_auth_codes' already exists
The only table that exists in the testing database is the migrations table. It looks as if it's checking the regular database and seeing this Passport table instead of checking the testing database. Did I miss something simple here?
php artisan ... commands will use your .env variables for configuration, so yes, unless you specified which database connection to use, it will use your default .env's DB_ variables.
You can define something like a .env.testing, then re-run as php artisan migrate --env=testing to use that file instead of your default one.
.env:
DB_CONNECTION=mysql
DB_DATABASE=database
...
# Host, Port, Username, Password,
.env.testing:
DB_CONNECTION=mysql
DB_DATABASE=testing
...
# Host, Port, Username, Password,
I upload my project on C-panel and set my connection for database in my env file, it was ok for me with the same settings, but now i don't know why it's happening, this is error :
SQLSTATE[HY000] [1045] Access denied for user 'root'#'localhost' (using password: NO) (SQL: select *
from `permissions`)
And this is my env file settings for database :
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=thermota_db
DB_USERNAME=thermota_user
DB_PASSWORD= { my password }
i don't know this permissions in error, is my permissions_table ?
and why error for this table ?
Multiple reasons can be the cause.
This can happen when the server has already been started before updating database details on your .ENV file.
It could also be from inputting wrong database authentication details.
Solution
Restart the server anytime you update values on your .ENV file.
Ensure you use the correct authentication details or better still create a new database user.
Run this command:
php artisan config:cache
You are trying to use a different user that means that your root value is not used.
You need to cache your env field to use the values in it. That goes for every change you make as well.
if ur on online server do the following steps :
1 - locate to : /vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php
2 - add thoes line of code on the begining of this function : createConnection($dsn, array $config, array $options)
3 - code to add : \Artisan::call('config:cache');
4 - refresh ur home page
5 - remove the "\Artisan::call('config:cache');" line code
6 - enjoye ^^
I had the same issue and I couldn't run config:cache artisan command even with
Artisan::call('config:cache');.
So I done this and solved my issue:
artisan config:cache caches all files from /config into a single array that it stores. It then reads all config variables from that array and ignores anything in .env or the /config files until you recach them. That's why it still works after deleting .env.
https://laravel.com/docs/5.6/configuration#configuration-caching
If you don't have ssh access to your live server, you'd just need to delete the bootstrap/cache/config.php file, which is the cache file config:cache generates.
I am creating my very first project and I want to use my local php environment instead of Hemestead.
I created the project and now I have to create the database. I'mtrying to follow the steps of this link "https://laravel.com/docs/5.1/quickstart" and want to execute this command: php artisan migrate.
When executing I take this error:
Access denied for user 'homestead'#'localhost' (using password: YES)
I read this: Access denied for user 'homestead'#'localhost' (using password: YES)
but I don't understand something. What to put instead of:
DB_HOST=yourHostName
DB_DATABASE=yourDatabaseName
DB_USERNAME=yourDatabaseUsername
DB_PASSWORD=youPassword
So how to find my database name, hostname etc?
I repeat I am not using Homestead.
Please be sure that you have homestead db in your phpmyadmin. If don't, please create a new one. And than, go to .env file (this is the default of mysql) fill your username database with root, and the password is (empty). I had a same problem with you about 1 or 2 months ago. I just created a new one db because I have no homestead db in my phpmyadmin. I hope this helps.
If you did not change anything in your homestead configuration, those are the values
DB_HOST=localhost
DB_DATABASE=homestad
DB_USERNAME=homestad
DB_PASSWORD=secret
If you are not sure about it, SSH into your homestead box and try to login using
mysql -uhomestead -psecret
Also try
mysql -uroot -psecret
And if it works you have to change them to
DB_HOST=localhost
DB_DATABASE=homestad
DB_USERNAME=root
DB_PASSWORD=secret
If it doesn't login, you probably will have to recover your MySQL password:
http://dev.mysql.com/doc/refman/5.7/en/resetting-permissions.html