我的 Laravel 项目有问题。我几个小时前开始使用它,但遇到了 SQL 错误:SQLSTATE[HY000] [2002] 连接被拒绝我已经搜索了几个小时,只发现密码错误或端口错误,但我检查了一下,这对我来说没问题。这是 .env 文件:DB_CONNECTION=mysqlDB_HOST=localhostDB_PORT=3302DB_DATABASE=test_techniqueDB_USERNAME=rootDB_PASSWORD=这是 .env.example 文件:DB_CONNECTION=mysqlDB_HOST=localhostDB_PORT=3302DB_DATABASE=test_techniqueDB_USERNAME=rootDB_PASSWORD=这是database.php:'mysql' => [ 'driver' => 'mysql', 'url' => env('DATABASE_URL'), 'host' => env('DB_HOST', 'localhost'), 'port' => env('DB_PORT', '3302'), 'database' => env('DB_DATABASE', 'test_technique'), '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'), ]) : [], ],并检查 mysql 的端口:Test for TCPYour port 3302 is used by a processus with PID = 2292The processus of PID 2292 is 'mysqld.exe' Session: ServicesThe service of PID 2292 for 'mysqld.exe' is 'N/A'N/A means that there are no service related to PID 2292Processus 'mysqld.exe' is launched by service 'wampmysqld64' with PID 5048Test for TCPv6Your port 3302 is used by a processus with PID = 2292The processus of PID 2292 is 'mysqld.exe' Session: ServicesThe service of PID 2292 for 'mysqld.exe' is 'N/A'N/A means that there are no service related to PID 2292Processus 'mysqld.exe' is launched by service 'wampmysqld64' with PID 5048我从未更改过 mysql 中的用户名和密码,所以我不知道为什么会出现此错误PS:在另一个站点中,当我像这样使用 PDO 时,它可以工作:new PDO("mysql:host=localhost:3302;dbname=test_technique;charset=utf8", "root", "",array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
1 回答
慕标5832272
TA贡献1966条经验 获得超4个赞
MySQL 的默认端口是 3306 而不是 3302,除非您在 php.ini 中更改了端口,否则您必须这样使用
DB_PORT = 3306
运行这个命令
php artisan config:clear
而不是使用
php artisan serve
使用
php -S 127.0.0.1:8000 -t public/
这可能会有所帮助,因为如果您使用 artisanserve 并对 env 进行更改,您必须终止该服务并再次运行。
- 1 回答
- 0 关注
- 159 浏览
添加回答
举报
0/150
提交
取消