SQLSTATE[28000] [1045] Access denied for user 'root'

Viewed 4535

I have my project ready and I have just uploaded to a shared hosting server. Everything works perfectly fine on my local machine but the page is displaying the error: "SQLSTATE[28000] [1045] Access denied for user 'root'@'localhost' (using password: NO)"

I have checked my password and username and they are both correct. The server requirements are also as I already have 2 other Laravel sites running with the same host.

I have done php artisan config:cache php artisan cache:clear But no headway.

What could be causing this and how do I get it solved? I earnestly need a solutions as this has kept me sleepless for nights now.

4 Answers

try to with these 3 artisan command.

1) php artisan config:clear

2) php artisan cache:clear

3) php artisan config:cache

different config? it's saying your password is empty ;)

"I have checked my password and username"

"(using password: NO)"

app/config/database.php:

    'mysql' => array(
    'read' => array(
        'host' => '192.168.1.1',
    ),
    'write' => array(
        'host' => '196.168.1.2'
    ),
    'driver'    => 'mysql',
    'database'  => 'database',
    'username'  => 'root',
    'password'  => '<insert password here?>',
    'charset'   => 'utf8',
    'collation' => 'utf8_unicode_ci',
    'prefix'    => '',
),

Open terminal and type

sudo mysql -u root -p

It will prompt you in mysql, here you can fire any mysql commands.

Use mysql table for change table type, so we can use empty password. Bellow is command for it

USE mysql;

Now we change type of table by following command

UPDATE user SET plugin='mysql_native_password' WHERE User='root';

now we have to flush the privileges, because we have used UPDATE. If you use INSERT, UPDATE or DELETE on grant tables directly you need use FLUSH PRIVILEGES in order to reload the grant tables.

FLUSH PRIVILEGES;

now exit from mysql by following command

exit;

now restart mysql server by following command

service mysql restart

Hope this may help

Thank you.

Anytime you deploy a project, you should typically run the php artisan config:cache command as part of your production deployment routine. I suggest you

  1. Remove the configuration cache file
  2. Flush the application cache
  3. Create a cache file for faster configuration loading

To do this, run the following Artisan commands on your command line

php artisan config:clear
php artisan cache:clear
php artisan config:cache

Where you don't have access to the command line on your server, you can programmatically execute commands by adding the following to your routes:

Route::get('/clear-cache', function() {
    $exitCode = Artisan::call('config:clear');
    $exitCode = Artisan::call('cache:clear');
    $exitCode = Artisan::call('config:cache');
    return 'DONE'; //Return anything
});

And then call the clear-cache route from your browser.

Related