This guide will help you troubleshoot database connection issues with your Campus Bridge LMS deployment on Render.
Problem: Database connection fails because environment variables are not configured.
Solution:
- Go to your Render dashboard
- Navigate to your web service
- Go to "Environment Variables" section
- Add the following variables:
MYSQL_HOST=your-database-host MYSQL_PORT=3306 MYSQL_USER=your-database-username MYSQL_PASSWORD=your-database-password MYSQL_DATABASE=lms
Problem: PlanetScale requires specific configuration.
Solution:
- In your PlanetScale dashboard:
- Create a new password for your database
- Copy the host, username, and password
- Set these environment variables in Render:
MYSQL_HOST=aws.connect.psdb.cloud MYSQL_PORT=3306 MYSQL_USER=your-planetscale-username MYSQL_PASSWORD=your-planetscale-password MYSQL_DATABASE=your-planetscale-database-name
Problem: The required tables don't exist in your database.
Solution:
- Connect to your database using a MySQL client
- Run the initialization script:
CREATE DATABASE IF NOT EXISTS lms; USE lms; CREATE TABLE IF NOT EXISTS learning_resources ( id INT AUTO_INCREMENT PRIMARY KEY, title VARCHAR(255) NOT NULL, file_path VARCHAR(255) NOT NULL ); CREATE TABLE IF NOT EXISTS users ( id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(255) NOT NULL, email VARCHAR(255) UNIQUE NOT NULL, password VARCHAR(255) NOT NULL, is_verified TINYINT(1) DEFAULT 0, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP );
Problem: Database is not accessible from Render.
Solution:
- For PlanetScale: Ensure you're using the correct connection details
- For other providers: Make sure the database accepts connections from external IPs
- Check firewall settings if hosting your own database
Problem: Database username or password is incorrect.
Solution:
- Double-check your database credentials
- Make sure you're using the correct database name
- Test the connection locally with the same credentials
Problem: Email verification is not working, preventing user login.
Solution:
- Set these environment variables in Render:
EMAIL_SERVICE=gmail EMAIL_USER=your-email@gmail.com EMAIL_PASS=your-app-password EMAIL_FROM=your-email@gmail.com APP_URL=https://your-app-name.onrender.com - For Gmail, you need to generate an App Password:
- Go to your Google Account settings
- Navigate to Security
- Enable 2-Factor Authentication
- Generate an App Password for "Mail"
Problem: Users can register but cannot login because they haven't verified their email.
Solution:
- Ensure email configuration is correct (see above)
- For development/testing, you can manually verify users by running:
UPDATE users SET is_verified = 1 WHERE email = 'user@example.com';
- Or temporarily disable email verification by modifying the login query in server.js
Problem: Missing columns or incorrect table structure.
Solution:
- Verify your users table has all required columns:
DESCRIBE users;
- Ensure it has these columns:
- id (INT, AUTO_INCREMENT, PRIMARY KEY)
- name (VARCHAR)
- email (VARCHAR, UNIQUE)
- password (VARCHAR)
- is_verified (TINYINT, DEFAULT 0)
- created_at (TIMESTAMP, DEFAULT CURRENT_TIMESTAMP)
After deployment, visit:
https://your-app-name.onrender.com/db-status.html
Use the buttons to:
- Check Connection: Test basic database connectivity
- Check Tables: Verify that required tables exist
- Check Users: See how many users are registered
For specific authentication issues, visit:
https://your-app-name.onrender.com/auth-troubleshooting.html
This page provides step-by-step guidance for resolving registration and login problems.
Visit the database status page and click "Check Connection". If it fails, the error message will show the connection details being used.
- PlanetScale: Check connection strings in the dashboard
- Railway: Verify database credentials
- Self-hosted: Ensure the database is accessible from external IPs
If tables don't exist, connect to your database and run the SQL commands from the initialization script.
- Go to your Render dashboard
- Navigate to your web service
- Check the "Logs" tab for any database-related error messages
To test your database connection locally:
-
Create a .env file with your database credentials:
MYSQL_HOST=your-host MYSQL_USER=your-username MYSQL_PASSWORD=your-password MYSQL_DATABASE=lms -
Run the application:
npm start
-
Visit http://localhost:3000/db-status.html to test the connection
If you continue to have issues:
- Check the Render logs for detailed error messages
- Verify all environment variables are correctly set
- Contact your database provider for connection details
- Reach out to: connect@campusbridge.io