How to connect Laravel to MAMP mysql on Mac - php

Here is my Laravel Database config
DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=8889
DB_DATABASE=carnet
DB_USERNAME=root
DB_PASSWORD=root
But i keep getting this error
SQLSTATE[HY000] [1045] Access denied for user 'root'#'localhost'
(using password: YES)

Try changing the host from localhost to 127.0.0.1 and check if it connects.

Related

Laravel PDOException(code: 1045) yet credentials work in phpmyadmin

An PDOException(code: 1045) error occurs when laravel connects to mysql yet the credentials allow me to log in via phpmyadmin suggesting the credentials are correct.
Error message:
(PDOException(code: 1045): SQLSTATE[HY000] [1045] Access denied for user 'host.domain.com'#'localhost' (using password: YES)
.env file:
DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=host.domain.com
DB_USERNAME=host.domain.com
DB_PASSWORD=password_here
PHP version is 7.2.31
Laravel Framework version is 6.13.1
CentOS server (note cant make the error occur on my Windows laptop with WAMP)
If I quoted the DB_DATABASE, DB_USERNAME and DB_PASSWORD fields in .env the application worked. I have no further explanation of why considering there are no spaces in the values for these fields.
Revised .env file:
DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE="host.domain.com"
DB_USERNAME="host.domain.com"
DB_PASSWORD="password_here"

Problem with DB after cloning project from repo // PHP laravel

I have a problem with my Laravel project. After cloning the repo from git I did
npm install
composer install
php artisan migrate I have an error:
In Connection.php line 664:
SQLSTATE[HY000] [1045] Access denied for user 'root'#'localhost'
(using password: YES) (SQL: select * from languages where status =
1)
In Connector.php line 70:
SQLSTATE[HY000] [1045] Access denied for user 'root'#'localhost'
(using password: YES)
I've added few changes to .env file only
APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:q/o7QZeznstW1iBW65t8F7usVPI1oA9osHGaCa6uONU=
APP_DEBUG=true
APP_URL=localhost
LOG_CHANNEL=stack
DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=8889
DB_DATABASE=newDB
DB_USERNAME=root
DB_PASSWORD=root
I am using mamp on mac os for my web environment.
Error Screenshot:
Try adding this to your .env file
DB_SOCKET=/Applications/MAMP/tmp/mysql/mysql.sock
I use MAMP too and always need this inside my .env files
Open the .env file and edit it.
APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:q/o7QZeznstW1iBW65t8F7usVPI1oA9osHGaCa6uONU=
APP_DEBUG=true
APP_URL=http://localhost
LOG_CHANNEL=stack
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE= // Your Database Name
DB_USERNAME= // Yout Database Username
DB_PASSWORD= // Your Database Password
NOTE: If no password is set on the database, clear it DB_PASSWORD
This error basically comes from the after changes in the .env file:
SQLSTATE[HY000] [1045] Access denied for user 'root'#'localhost'
(using password: YES)
After completion of .env edit, must be clear cache: php artisan config:cache

When I type "php artisan migrate" in terminal, I see error

When I type "php artisan migrate" in terminal I see the error below:
In Connection.php line 664:
SQLSTATE[HY000] [1045] Access denied for user 'root'#'localhost' (using password: YES) (SQL: select * from information_schema.tables where table_schema = laravel and table_name = migrations)
In Connector.php line 67:
SQLSTATE[HY000] [1045] Access denied for user 'root'#'localhost' (using password: YES)
I'm using mac and Mamp Pro,
**Some other informations: **
php artisan serve => Laravel development server started: http://127.0.0.1:8000
.env file =>
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel
DB_USERNAME=root
DB_PASSWORD=1234
In phpMyAdmin top of all things writed =>
Server: localhost:8889
Local host address when mamp pro ran =>
http://localhost:8888/phpMyAdmin/
In phpMyAdmin =>
DB name: laravel
Username: root
Pass: 1234
This happens when your credentials cannot connect to the defined sql host.
Ideas:
Can you connect with your db credentials using Sequel Pro? https://www.sequelpro.com.
Be sure you grant laravel db permissions for your user.
Try changing
DB_HOST=127.0.0.1
to
DB_HOST=localhost

Laravel access denied but I can connect using phpmyadmin or normal php query

I'm getting this error message when I try to migrate using artisan
[Illuminate\Database\QueryException]
SQLSTATE[HY000] [1045] Access denied for user 'myuser'#'mycomputerip'
(using password: YES) (SQL: select * from information_schema.tables where t
able_schema = database and table_name = migrations)
[PDOException]
SQLSTATE[HY000] [1045] Access denied for user 'myuser'#'mycomputerip'
(using password: YES)
I have tryed to use my local xampp mysql database and that did also not work.
I'm using mariadb on the server which is the one I'm trying to connect to.
env file (default chagnes bcus security)
DB_CONNECTION=mysql
DB_HOST=serverip
DB_PORT=3306
DB_DATABASE=database
DB_USERNAME=myuser
DB_PASSWORD=mysecurepassword
I am able to connect using a normal php mysqli connection or with phpmyadmin
DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=database
DB_USERNAME=myuser
DB_PASSWORD='' or DB_PASSWORD=mypassword
And
php artisan config:clear
and Then Restart Your serve and Then Try it..

PDOException SQLSTATE[28000] [1045] Access denied for user 'homestead'#'localhost'

I am new in Laravel 5.2.
I am getting following error:
[PDOException]
SQLSTATE[28000] [1045] Access denied for user 'homestead'#'localhost' (usin
g password: YES)
While I execute following command:
php artisan migrate
I am running application using vagrant on windows PC.
Please let me know why I am getting above error.
You are getting above error because on your .env file. If you open that from your project base directory then you will following default configuration:
DB_CONNECTION=mysql
DB_HOST=localhost
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret
Just change above values according to your development environment. Try again, Hopefully that would resolve your issue.
You must set the database connection in .env file.

Categories