我的 Laravel 项目有问题。我几个小时前开始使用它,但遇到了 SQL 错误:
SQLSTATE[HY000] [2002] 连接被拒绝
我已经搜索了几个小时,只发现密码错误或端口错误,但我检查了一下,这对我来说没问题。
这是 .env 文件:
DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3302
DB_DATABASE=test_technique
DB_USERNAME=root
DB_PASSWORD=
这是 .env.example 文件:
DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3302
DB_DATABASE=test_technique
DB_USERNAME=root
DB_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 TCP
Your port 3302 is used by a processus with PID = 2292
The processus of PID 2292 is 'mysqld.exe' Session: Services
The service of PID 2292 for 'mysqld.exe' is 'N/A'
N/A means that there are no service related to PID 2292
Processus 'mysqld.exe' is launched by service 'wampmysqld64' with PID 5048
Test for TCPv6
Your port 3302 is used by a processus with PID = 2292
The processus of PID 2292 is 'mysqld.exe' Session: Services
The service of PID 2292 for 'mysqld.exe' is 'N/A'
N/A means that there are no service related to PID 2292
Processus '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));
慕标5832272