I have the username: root and password: root. I cannot connect to my db whenever I type root in my password. It keeps saying ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: YES) However, when I press enter leaving the password empty, I can go in.
In my .env file I have:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=fin_book_09
DB_USERNAME=root
DB_PASSWORD=root
I also changed my config/database to:
'mysql' => [
'driver' => 'mysql',
'url' => env('DATABASE_URL'),
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'root'),
'password' => env('DB_PASSWORD', 'root'),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'prefix_indexes' => true,
'strict' => true,
'engine' => null,
'options' => extension_loaded('pdo_mysql') ? array_filter([
PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
]) : [],
],
I can't seem to understand why this is happening.
Check Your Database connection in PHPMyAdmin.
PHPMyAdmin Default
user name: 'root'
Password : ''
for password set,
SET PASSWORD FOR root#localhost = PASSWORD('your_root_password');
If you are serving your application by laravel command php artisan serve.
Then close that and serve again.
And if still not work try to regenerate your application key again.
php artisan key:generate
Hope it helps :)
Related
I try connect to remote Database and get an error "SQLSTATE[HY000] [1045] Access denied for user". I think the only reason why it happened is absence rights to the DB of user.
My env file
DB_CONNECTION=mysql
DB_HOST=80.241.222.228
DB_PORT=3306
DB_DATABASE=databaseName
DB_USERNAME=databaseUsername
DB_PASSWORD=mypass
My config/database.php file
'mysql' => [
'driver' => 'mysql',
'url' => env('DATABASE_URL'),
'host' => env('DB_HOST', '80.241.222.228'),
'port' => env('DB_PORT', '3306'),
'database' => 'databaseName',
'username' => 'databaseUsername',
'password' => 'mypass',
]
Thanks for your time and help :)
I have this in env file
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE={db_name}
DB_USERNAME=root
DB_PASSWORD={db_password}
I config/database.php
'default' => env('DB_CONNECTION', 'mysql'),
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'strict' => false, //true is default
'engine' => null,
],
That's how I got the password:
cat /root/.digitalocean_password
But I get
SQLSTATE[HY000] [1698] Access denied for user 'root'#'localhost' (SQL: select * from `users` where `email` ....
I even cleared the password value in env file but ti doesn't work too. Any help please? Thanks in advance.
To backtrace your issue. try to connect via SSH on your database server . then try to do this
$ sudo mysql -uroot -p
$ password : ******** (enter your password here)
If you were able to connect, probably you shouldn't have any problem on your app level.
second option is : try to use host "localhost" instead of "127.0.0.1" as your root username might only pointed to #localhost instead of #127.0.0.1
Here's the solution I got:
I had to create another user rather than root and add all permissions to that new user which will sure have a new password. I used that username and password in .env file for database connection and it worked fine.
My env Database is Right but I get this error
SQLSTATE[28000] [1045] Access denied for user 'elsharkawyazq_climate_app'#'localhost' (using password: YES)
I'm using laravel 5.8 on PHP 7.3 on my server
I tried other working database didn't work so env file data is correct but I don't know why this is happening
My Env
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=elsharkawyazq_climate_app
DB_USERNAME=elsharkawyazq_climate_app
DB_PASSWORD=SomePassword!####!
My Database
'mysql' => [
'driver' => 'mysql',
'url' => env('DATABASE_URL'),
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'elsharkawyazq_climate'),
'username' => env('DB_USERNAME', 'elsharkawyazq_test'),
'password' => env('DB_PASSWORD', 'SomePassword!####!'),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'prefix_indexes' => true,
'strict' => false,
'engine' => null,
'options' => extension_loaded('pdo_mysql') ? array_filter([
PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
]) : [],
],
i used Xampp on local and everything was fine
The pound sign acts as a comment. You cannot use the pound sign (#) as a character in a .env file when it is not escaped. Surround your password with quotes:
DB_PASSWORD="Your-password-with-###-here"
When I enter the php artisan tinker environment, I can load the environment variables from the .env and when I have a pound sign in a value, it acts as a comment. When put inside quotes it does not.
In your .env DB_PASSWORD don't use any (!) and (#) character. You can use (#) or (%) character in your password. So remove these characters from your DB_password.
DB_PASSWORD="Use only the laravel allowed db password allowed characters"
I think it should work for all lavavel lovers.
I know there is a lot of topics on this error but it seems that I already try almost everything and it doesn't work at all.
So I've set up my .env file like this:
APP_NAME=Neuralia
APP_ENV=local
APP_KEY=(key)
APP_DEBUG=true
APP_LOG_LEVEL=debug
APP_URL=http://127.0.0.1:8000
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=neuralia
DB_USERNAME=username
DB_PASSWORD=password
and my config/database.php like this:
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'neuralia'),
'username' => env('DB_USERNAME', 'username'),
'password' => env('DB_PASSWORD', 'password'),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'strict' => true,
'engine' => null,
],
I tried with host => localhost, I cleared my config / cache and dump-autoload but I still get the error when I try to create a user from the register form.
I can use php artisan migrate:refresh etc but not the register / login stuff :/
do you have any ideas please?
Thanks
I install laravel on Ampps (windows 10) with .
it works.
But Now I want connect to mysql.
I create a 'blog' DB and change these two files:
.env file:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=blog
DB_USERNAME=root
DB_PASSWORD='mysql'
and /config/database.php :
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'blog'),
'username' => env('DB_USERNAME', 'root'),
'password' => env('DB_PASSWORD', 'mysql'),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'strict' => false,
'engine' => null,
],
but still I get the below message when I want to migrate:
C:\Program Files (x86)\Ampps\www\blog>php artisan migrate
[Illuminate\Database\QueryException]
SQLSTATE[HY000] [1045] Access denied for user 'root'#'localhost' (using password: YES) (SQL: select * from information_schema.tables where table_schema = blog and table_name = migrations)
[PDOException]
SQLSTATE[HY000] [1045] Access denied for user 'root'#'localhost' (using password: YES)
Password should be this
DB_PASSWORD=mysql
Not this
DB_PASSWORD='mysql'
You should write this
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => true,
'engine' => null,
],
and your env file is
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=blog
DB_USERNAME=root
DB_PASSWORD=mysql
Also restart your server.
First change your password in .env file from DB_PASSWORD='mysql' to DB_PASSWORD=mysql without single quotation. Second you should set more secure passwords for your databases.
You should give root user access to your database.
GRANT ALL PRIVILEGES ON blog.* TO 'root'#'localhost' identified by 'mysql';
FLUSH PRIVILEGES;
Try running below command
php artisan cache:clear
This should update the settings saved in the cache.