【发布时间】:2022-03-21 19:06:09
【问题描述】:
在我的本地环境中,将数据插入我的数据库是可行的。但是在我的远程服务器上它不起作用。
我已经更改了我的远程 .env 和 database.php 文件,以便我的远程数据库和服务器可以正常工作。我可以通过mysqlworkbench 连接到数据库,没有任何问题。
但是我收到以下错误:
异常:“Illuminate\Database\QueryException” 文件:“/var/www/html/go/releases/1/vendor/laravel/framework/src/Illuminate/Database/Connection.php” 线路:664 消息:“SQLSTATE[HY000] [2002] 连接被拒绝(SQL:插入
temp_users(energy,diet,car,shortFlights,longFlights,longFlights,country,@ 987654331@,updated_at,created_at) 值 (1.13, 1.7, 0.55, 0, 0, test51@mail.com, 荷兰, 5.38, 2019-09-10 15:27:41, 2019-09-10 15 :27:41))” 追踪:[,…]
.env(用默认值替换了一些值,以保护隐私)。
APP_NAME=thename
APP_ENV=production
APP_KEY=the key
APP_DEBUG=true
APP_LOG_LEVEL=error
APP_URL=theurl
LOG_CHANNEL=stack
DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=thedatabasename
DB_USERNAME=theusername
DB_PASSWORD=thepassword
BROADCAST_DRIVER=log
CACHE_DRIVER=file
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_LIFETIME=120
REDIS_HOST=localhost
REDIS_PASSWORD=null
REDIS_PORT=6379
MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_APP_CLUSTER=mt1
MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
database.php(重要部分)
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'thedatabasename'),
'username' => env('DB_USERNAME', 'theusername'),
'password' => env('DB_PASSWORD', 'thepassword'),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'prefix_indexes' => true,
'strict' => true,
'engine' => null,
],
数据库名称正确。该表存在,所有字段也存在。提前致谢。
【问题讨论】:
-
将 DB_HOST 更改为您的远程服务器 IP 而不是 localhost
-
@PalakJadav 当我将
DB_HOST都更改为我的 ip 时,我仍然遇到同样的问题。 -
运行命令 php artisan config:clear
-
它告诉我
Could not open input file: artisan。我也从未使用 php artisan 进行本地开发。