Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access denied for user 'root'@'localhost' - Laravel

I have an application with Laravel 4, that runs in localhost correctly, but when I uploaded it in my host I received the error .

app>config>database.php file is:

'mysql' => array(
        'driver'    => 'mysql',
        'host'      => '127.0.0.1',
        'database'  => 'forum',
        'username'  => 'root',
        'password'  => '',
        'charset'   => 'utf8',
        'collation' => 'utf8_unicode_ci',
        'prefix'    => '',
    ),

And bootstrap>start.php is:

$env = $app->detectEnvironment(array(
'local' => array('homestead'),
));
like image 220
atf.sgf Avatar asked Apr 26 '15 09:04

atf.sgf


4 Answers

This worked for me:

php artisan config:clear

Even though I changed the config details in the .env file, I was getting the Access denied error. Running the above command will clear configuration cache file and hence laravel will read the fresh data from the .env file.

like image 56
Raghav Avatar answered Nov 09 '22 15:11

Raghav


You must find out the credentials of Database host, Database Name , Database Username and Database Password . (If any prefix for tables too) and then replace it with the current credentials.

Use the concept of environments and store values in ENV variables :

http://laravel.com/docs/4.2/configuration

You can store Env Variables as array in .{ENV_NAME}.env.php and access those variables as $_ENV['variable_name'].

like image 27
Ajay Kumar Ganesh Avatar answered Nov 09 '22 15:11

Ajay Kumar Ganesh


Maybe you should add double-quotes for password in env:

# Config: database
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=db_name
DB_USERNAME=db_user
DB_PASSWORD="db_password"

and

php artisan config:clear
like image 42
bravohex Avatar answered Nov 09 '22 14:11

bravohex


Check your mysql database is running perfectly or not. Then check you db user root in mysql with no password and restart your server.

like image 2
Iftakharul Alam Avatar answered Nov 09 '22 16:11

Iftakharul Alam