简体   繁体   中英

My Laravel project don't conect to XAMPP DataBase

I've followed good tutorials on the web and I do make, I've made step by step its advices and I don't achive to conect my laravel framework to XAMPP.. I don't have idea what's going on.. I've written down the .env and config/database.php with the same data configurations (DB_DATABASE= styde_curso, DB_USERNAME= root, and DB_PASSWORD= ).

.env

APP_NAME=Prueba
APP_ENV=local
APP_KEY=base64:MWU6YadaT17Ga1m3hrtOQqYq6pIwOgrNWQe+mJazyw0=
APP_DEBUG=true
APP_URL=homestead.test
LOG_CHANNEL=stack
DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=styde_curso
DB_USERNAME=root
DB_PASSWORD=

config/database.php

'mysql' => [

            'driver' => 'mysql',
            'host' => env('DB_HOST', '127.0.0.1'),
            'port' => env('DB_PORT', '3306'),
            'database' => env('DB_DATABASE', 'styde_curso'),
            'username' => env('DB_USERNAME', 'root'),
            'password' => env('DB_PASSWORD', ''),
            'unix_socket' => env('DB_SOCKET', ''),
            'charset' => 'utf8mb4',
            'collation' => 'utf8mb4_unicode_ci',
            'prefix' => '',
            'strict' => true,
            'engine' => null,
        ],

Although I'd applied "php artisan config:clear" I'm getting the same result "ERROR" I've copied the error that git hub notices me:

vagrant@homestead:~/code/Prueba$ php artisan config:clear Configuration cache cleared! vagrant@homestead:~/code/Prueba$ php artisan migrate

Illuminate\\Database\\QueryException : SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: NO) (SQL: select * from information_schema.tables where table_schema = styde_curso and table_name = migrations)

at

/home/vagrant/code/Prueba/vendor/laravel/framework/src/Illuminate/Database/Connection.php: 664

660|         // If an exception occurs when attempting to run a query, we'll format the error
661|         // message to include the bindings with SQL, which will make this exception a
662|         // lot more helpful to the developer instead of just the database's errors.

663|         catch (Exception $e) {
664|             throw new QueryException(
665|                 $query, $this->prepareBindings($bindings), $e
666|             );
667|         }
668|

Exception trace:

1 PDOException::("SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: NO)") /home/vagrant/code/Prueba/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php : 68

2
PDO::__construct("mysql:host=localhost;port=3306;dbname=styde_curso", "root", "", []) /home/vagrant/code/Prueba/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php : 68

I'll wait your help or whomever can help me.. Thanx.

Sometimes this problem comes when you make changes to your .env file and not restarting the server. I would suggest you change 'host' => env('DB_HOST', '127.0.0.1'), to localhost, then restart your server, since the config/database is also written localhsot

I would suggest setting your DB_HOST to 127.0.0.1

DB_HOST=127.0.0.1

I would also suggest setting a password for the database root user if you have not already, this is just good practice. Be sure to update the .env file with the new password if you choose to do so.

The error is telling you the login failed:

SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: NO)

The error is most likely either as a result of incorrect credentials (missing or wrong username/password). Or incorrect access, in other words, your user (in this case root) may have privileges as root@127.0.0.1 but not as root@localhost.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM