raii6926
connection refused
hi when i see deploy log it say :
Starting Container
2024/07/11 19:21:40 MYSQLUSER:
2024/07/11 19:21:40 MYSQLPASSWORD:
2024/07/11 19:21:40 MYSQLHOST:
2024/07/11 19:21:40 MYSQLPORT:
2024/07/11 19:21:40 MYSQLDATABASE:
2024/07/11 19:21:40 /app/database/db.go:44
[error] failed to initialize database, got error dial tcp :0: connect: connection refused
2024/07/11 19:21:40 DB Connection Error:dial tcp :0: connect: connection refused
the print not give the key from my .env its that the problem?
14 replies
connection refused
i change be like this :
databaseURL := os.Getenv("DATABASE_URL")
var dsn string
if databaseURL != "" {
dsn = databaseURL
} else {
dbUsername := os.Getenv("MYSQLUSER")
dbPassword := os.Getenv("MYSQLPASSWORD")
dbHost := os.Getenv("MYSQLHOST")
dbPort := os.Getenv("MYSQLPORT")
dbName := os.Getenv("MYSQLDATABASE")
// Debug prints to verify environment variables
log.Println("MYSQLUSER:", dbUsername)
log.Println("MYSQLPASSWORD:", dbPassword)
log.Println("MYSQLHOST:", dbHost)
log.Println("MYSQLPORT:", dbPort)
log.Println("MYSQLDATABASE:", dbName)
// Construct the DSN from individual environment variables
dsn = dbUsername + ":" + dbPassword + "@tcp(" + dbHost + ":" + dbPort + ")/" + dbName + "?charset=utf8mb4&parseTime=True&loc=Local"
}
db, err := gorm.Open(mysql.Open(dsn), &gorm.Config{})
if err != nil {
log.Fatal("DB Connection Error:", err)
}
its that okey?
14 replies
connection refused
so why the log in railways always say :
[error] failed to initialize database, got error dial tcp :0: connect: connection refused
2024/07/11 19:06:42 DB Connection Errordial tcp :0: connect: connection refused
container event container died
14 replies