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 :)
Related
I'm trying to get my laravel app and the mysql database in XAMPP connected and struggling. On http://localhost:8080/aws-upload/public/ I get the following error:
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'mydb2.files' doesn't exist (SQL: select * from `files`)
It then prompts me to migrate, if I migrate on the chrome button provided by laravel the site appears and starts to work, however if I try to migrate through the terminal I get:
SQLSTATE[HY000] [2002] Connection refused (SQL: select * from information_schema.tables where table_schema = mydb2 and table_name = migrations and table_type = 'BASE TABLE')
I've created the database in phpMyAdmin called mydb2 and updated my .env file to:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=mydb2
DB_USERNAME=root
DB_PASSWORD=
This is my database.php file:
'mysql' => [
'driver' => 'mysql',
'url' => env('DATABASE_URL'),
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'mydb2'),
'username' => env('DB_USERNAME', 'root'),
'password' => env('DB_PASSWORD', ''),
'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'),
]) : [],
],
Thanks
In your database.php file:
'host' => env('DB_HOST', 'localhost'), try changing localhost to 127.0.0.1
In your .env file:
At the top of the file, you'll see it says APP_URL=http://example.com - change the url to APP_URL=http://127.0.0.1
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 :)
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.
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.
When my .env file is like this:
DB_HOST=127.0.0.1
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret
Terminal php artisan migrate works successful but on localhost test, it throws:
PDOException in Connector.php line 50:
SQLSTATE[HY000] [2002] Connection refused
But when my .env file is like this:
DB_HOST=localhost
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret
On localhost everything (registration) works well however php artisan migrate on terminal throws:
[PDOException] SQLSTATE[HY000] [2002] No such file or directory
My database.php file:
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
'database' => env('DB_DATABASE', 'homestead'),
'username' => env('DB_USERNAME', 'homestead'),
'password' => env('DB_PASSWORD', 'secret'),
'port' => '33060',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
],
Inside the VM the sql port is 3306. Outside of the homestead VM the host machine just has a forward to the SQL port on the homestead VM. That is why 33060 points to 3306.
Laravel Homestead Vagrant Box Database Problems
To fix the issue. Do the following:
.env
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret
database.php
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
'database' => env('DB_DATABASE', 'homestead'),
'username' => env('DB_USERNAME', 'homestead'),
'password' => env('DB_PASSWORD', 'secret'),
'port' => env('DB_PORT', 3306),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
],
That will get your browsing fixed. Now to run artisan commands, just do vagrant SSH and run them on the VM.