You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

新OpenShift环境下Redmine无法连接本地MySQL服务器求助

Troubleshooting Redmine MySQL Socket Connection Error on OpenShift

Hey there, let's work through this MySQL socket connection issue you're facing when deploying Redmine on OpenShift. The error Mysql2::Error: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) is a common one, and it's almost always related to how your Redmine is configured to reach the MySQL instance in the OpenShift environment.

Here are the key steps to fix this:

  • Switch from socket-based to TCP/IP connection
    In OpenShift, your MySQL database is almost certainly running as a separate Pod (not on the same node/container as Redmine), so local socket connections won't work. You need to update your database.yml to use TCP/IP instead:

    1. Remove the socket: /var/lib/mysql/mysql.sock line from your configuration.
    2. Add the host field set to the name of your MySQL service in OpenShift (you can find this with oc get services in your project namespace).
    3. Add the port field (default is 3306 unless you've modified the MySQL deployment).

    Example production configuration snippet:

    production:
      adapter: mysql2
      database: redmine_production
      host: mysql-service-name
      port: 3306
      username: your_db_username
      password: "your_db_password"
      encoding: utf8mb4
    
  • Verify database credentials and service reachability
    From your Redmine Pod, test if you can reach the MySQL service directly using the mysql client (if installed):

    mysql -h <mysql-service-host> -u <db-username> -p <db-name>
    

    If this fails, double-check your credentials, ensure the MySQL service is up, and confirm the database name matches what's in database.yml.

  • Check MySQL Pod status
    Make sure your MySQL Pod is in a Running state. Run oc get pods to check—if it's crashing or in a pending state, resolve those issues first (check logs with oc logs <mysql-pod-name> to debug startup errors).

  • Validate network policies
    Sometimes OpenShift network policies can block traffic between Redmine and MySQL. Ensure there's a policy in place that allows your Redmine Pod's namespace to access the MySQL service on port 3306.

After updating your database.yml, redeploy Redmine to apply the changes:

oc rollout restart deployment/redmine-deployment-name

Let me know if you hit any snags while working through these steps—I can help dig deeper if needed!

内容的提问来源于stack exchange,提问作者user3190036

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 08:02:08