How to Fix cPanel MySQL Errors — Database Connection Issues
DodaTech
Updated 2026-06-24
1 min read
In this tutorial, you'll learn about How to Fix cPanel MySQL Errors. We cover key concepts, practical examples, and best practices.
The Problem
MySQL is not working:
Error: MySQL connection refused.
or:
#1045 - Access denied for user 'username'@'localhost'.
Quick Fix
Step 1: Check MySQL status
systemctl status mysql
systemctl status mariadb
If not running:
systemctl restart mysql
Step 2: Reset MySQL root password
# From WHM or command line:
/scripts/restartsrv_mysql
mysqladmin -u root password 'new-password'
Step 3: Repair a specific database
mysqlcheck -r database_name -u root -p
Step 4: Check MySQL error log
tail -100 /var/lib/mysql/hostname.err
Step 5: Fix max_connections exceeded
# Check current connections:
mysqladmin -u root -p status
# Increase max_connections:
mysql -e "SET GLOBAL max_connections = 500;"
In my.cnf:
[mysqld]
max_connections = 500
Step 6: Repair MySQL if it crashes on start
# Safe mode repair:
mysqld_safe --skip-grant-tables &
mysql -u root -e "FLUSH PRIVILEGES;"
mysqlcheck -A -u root -p
Prevention
- Monitor MySQL connections regularly.
- Keep MySQL/MariaDB updated.
- Set reasonable max_connections in my.cnf.
Common Mistakes with mysql error
- Forgetting
deriving (Show, Eq)on custom data types needed for debugging - Placing the wildcard pattern first in case expressions, making all subsequent patterns unreachable
- Using
headandtailinstead of pattern matching, causing runtime errors on empty lists
These mistakes appear frequently in real-world CPANEL code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.
Practice Exercise
Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.
This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.
FAQ
← Previous
How to Fix cPanel FTP Connection Errors — File Transfer Issues
Next →
How to Fix cPanel PHP ini Configuration Errors
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro