Laravel 5.4.28 gives "SQLSTATE[HY000] [2002] Operation timed out" - php

I am getting the error
SQLSTATE[HY000] [2002] Operation timed out (SQL: select * from users where 1)
from any query I attempt to send to my database.
Running php artisan migrate runs completely fine from command line showing that my settings are correct! Whats going wrong?!
.env:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=vehiclexray
DB_USERNAME=root
DB_PASSWORD=kzurxsxz1
database.php:
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'database'),
'username' => env('DB_USERNAME', 'root'),
'password' => env('DB_PASSWORD', 'password'),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'strict' => true,
'engine' =>
]

Related

I uploaded a laravel project in cPanel and I'm getting this error: SQLSTATE[HY000] [1044] Access denied for user

Error: SQLSTATE[HY000] [1044] Access denied for user 'tfs_user'#'localhost' to database 'tfs' (SQL: select * from settings)
When i click login/registration page i'm getting this error. i can't understand what's the problem. I updated my .env file with correct database info.
.env file
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=tfs
DB_USERNAME=tfs_user
DB_PASSWORD=tfsdemo01
database.php file
'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', ''),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',<
'prefix_indexes' => true,
'strict' => true,
'engine' => null,
],
How can i solve this error, can anyone help me please.
If the mysql server is on the same server as your application use host as localhost
DB_HOST=localhost

I can't create migration Laravel5 Access denied for user 'homestead'#'localhost' (using password: YES)

Terminal show me this message:
my env:
my 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', 'laravelup'),
'username' => env('DB_USERNAME', 'root'),
'password' => env('DB_PASSWORD', '1'),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'strict' => true,
'engine' => null,
],
How can I solve this issue ?
Just change your .env file like this
DB_DATABASE=laravelup
DB_USERNAME=root
DB_PASSWORD= //blank here
And it will be working.
I maybe laravel configration cache problem.
If you type this command "php artisan config:clear" and try again, then it will be working.

SQLSTATE[HY000] [2002] cannot connect because the computer refused the connection

I am trying to run a website in lavarel but I keep getting the error message. I have entered the correct password and username while the error occurs that the connection was refused by the computer.
.env file
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=''
DB_USERNAME=''
DB_PASSWORD='' db, username and ps are filled in
config/database.php
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', 'localhost'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'strict' => true,
'engine' => null,
],
status

SQLSTATE[HY000] [1049] Unknown database - Database created, not functioning

I have this in my .env file
APP_ENV=local
APP_DEBUG=true
APP_KEY=m6twKy7Lr6KKFvVa7QgXUe78xfn08MLn
DB_HOST=localhost
DB_DATABASE=laravel1
DB_USERNAME=root
DB_PASSWORD=somepass
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 this is in my database.php
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
],
The database is created and I can see it in phpMyAdmin in browser.
But when I write php artisan migrate I get this error:
[PDOException]
SQLSTATE[HY000] [1049] Unknown database 'laravel1'
I have seen the answers on
Laravel Migration - Says unknown database, but it is created , but that didn't helped me.
Try specifying the MySQL port that you are using. Might work out. I had a similar issue like this. Be sure to give the appropriate port where MySQL is installed in ur system(default is 3306).
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'databasename'),
'username' => env('DB_USERNAME', 'root'),
'password' => env('DB_PASSWORD', 'root'),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
],

laravel 5 Access denied for user 'root'#' localhost' (using password: YES)

I am new to Laravel5. I tried to create migration table but I get this error
Error Log
This is the database.php
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'larashop'),
'username' => env('DB_USERNAME', 'root'),
'password' => env('DB_PASSWORD', 'melody'),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
'engine' => null,
],
and this is .env
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=larashop
DB_USERNAME=root
DB_PASSWORD=melody
Please help.
Your screenshot shows "localhost" and your code shows "127.0.0.1". MySQL treats "localhost" and "127.0.0.1" differently.
Make sure you have granted appropriate permissions for 'root'#'localhost' in your database.
http://dev.mysql.com/doc/refman/5.7/en/grant.html

Categories