Learn how to diagnose, troubleshoot, and resolve MySQL connection errors in ViciDial production environments, including configuration validation, permission management, and failover strategies.
Prerequisites
Before proceeding with this tutorial, ensure you have:
- A running ViciDial installation (v2.2.x or later)
- SSH access to your ViciDial server with sudo privileges
- Basic understanding of MySQL user management and permissions
- Knowledge of ViciDial directory structure and config files
- Access to system logs via
/var/log/asterisk/and MySQL error logs - A test extension or test account to validate connectivity
Supported configurations:
- Single ViciDial server with local MySQL
- Remote MySQL database setup
- High-availability MySQL clusters with multiple replicas
- Both IPv4 and IPv6 network configurations
Understanding ViciDial MySQL Architecture
ViciDial relies on MySQL for:
- Call logging (
vicidial_log,vicidial_closer_log) - Agent and campaign data (
vicidial_users,vicidial_campaigns) - Lead management (
vicidial_list) - Call recordings metadata (
recording_log) - Real-time agent status and queue information
- Configuration and telephony data
When MySQL connectivity fails, ViciDial cannot:
- Log calls or agent activity
- Load agent campaigns
- Store call recordings metadata
- Maintain agent status
- Process lead data
The agent screen will hang, dialers will fail to launch, and logs will fill with connection timeout errors.
Common ViciDial MySQL Connection Error Messages
Error 1: "Can't connect to MySQL server on 'localhost' (111)"
[ERROR] vicidial_manager[12345]: Can't connect to MySQL server on 'localhost' (111)
Connection refused
Cause: MySQL daemon is not running or not listening on the specified port.
Error 2: "Access denied for user 'vicidial'@'localhost' (using password: YES)"
[ERROR] astguiclient[9876]: Access denied for user 'vicidial'@'localhost' (using password: YES)
Cause: Incorrect password in config, wrong user permissions, or password mismatch between config and MySQL.
Error 3: "Can't connect to MySQL server on '192.168.1.50' (111)"
[ERROR] vicidial_manager: Can't connect to MySQL server on '192.168.1.50' (111) Connection refused
Cause: Remote MySQL server not listening on the network interface, firewall blocking, or skip-networking enabled.
Error 4: "Unknown database 'asterisk'"
[ERROR] astguiclient: Unknown database 'asterisk'
Cause: Database doesn't exist, name mismatch in config, or MySQL user lacks database privileges.
Error 5: "Too many connections"
[ERROR] vicidial_manager: Can't create a new thread (errno 11)
[ERROR] astguiclient: Too many connections
Cause: Connection pool exhausted, max_connections exceeded, or persistent connection leaks.
Step 1: Verify MySQL Service Status
Begin by confirming MySQL is running and accessible:
# Check if MySQL service is active
sudo systemctl status mysql
# Alternative for MariaDB
sudo systemctl status mariadb
# Manual start if not running
sudo systemctl start mysql
sudo systemctl enable mysql # Enable on boot
Expected output:
● mysql.service - MySQL Community Server
Loaded: loaded (/lib/systemd/mysql.service; enabled; vendor preset: enabled)
Active: active (running) since Mon 2024-01-15 09:23:45 UTC; 2min 34s ago
Verify MySQL is listening on the correct port and interface:
# Check listening ports
sudo netstat -tuln | grep 3306
# or using ss (newer systems)
sudo ss -tuln | grep 3306
Expected output for local connection:
tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN
Expected output for remote access:
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN
If MySQL is not bound to 0.0.0.0 or the specific network interface, edit /etc/mysql/mysql.conf.d/mysqld.cnf:
# Current (localhost only)
bind-address = 127.0.0.1
# Updated (allow remote connections)
bind-address = 0.0.0.0
# Or bind to specific interface
bind-address = 192.168.1.50
After changes, restart MySQL:
sudo systemctl restart mysql
sudo systemctl restart mariadb # If using MariaDB
Verify the change:
sudo ss -tuln | grep 3306
Step 2: Validate ViciDial MySQL Configuration
ViciDial stores database credentials in several locations. Check each configuration file:
Check astguiclient.conf
sudo cat /etc/astguiclient.conf | grep -i mysql
This should output:
MYSQLHOST=127.0.0.1
MYSQLLOGIN=vicidial
MYSQLPASS=*your_password*
MYSQLDATABASE=asterisk
MYSQLPORT=3306
Full file example:
# /etc/astguiclient.conf
MYSQLHOST=127.0.0.1
MYSQLLOGIN=vicidial
MYSQLPASS=vicidial_password_123
MYSQLDATABASE=asterisk
MYSQLPORT=3306
TIMEZONE=America/Chicago
PBX_IP=127.0.0.1
PBX_PORT=5038
PBX_USER=admin
PBX_PASS=admin_pass
Check vicidial_web.conf
sudo cat /var/www/html/vicidial/vicidial_web.conf | grep -i mysql
Typical output:
$DBhost = "127.0.0.1";
$DBuser = "vicidial";
$DBpass = "vicidial_password_123";
$DBname = "asterisk";
$DBport = 3306;
Check web-vicidial.conf (API/remote integrations)
sudo cat /usr/share/astguiclient/web-vicidial.conf | head -20
All three should reference the same database, user, host, and port.
Step 3: Verify MySQL User Permissions
Connect to MySQL as root and validate the vicidial user exists with correct permissions:
# Connect to MySQL as root
sudo mysql -u root -p
# Enter root password when prompted
Once connected, run these SQL commands:
-- Show all MySQL users
SELECT user, host FROM mysql.user WHERE user LIKE 'vicidial%';
-- Show current vicidial user permissions (replace localhost with your host)
SHOW GRANTS FOR 'vicidial'@'localhost';
-- Check from remote host (if applicable)
SHOW GRANTS FOR 'vicidial'@'192.168.1.50';
SHOW GRANTS FOR 'vicidial'@'%';
Expected permission output:
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER
ON `asterisk`.* TO 'vicidial'@'localhost'
IDENTIFIED BY PASSWORD '*[hashed_password]';
If the vicidial user doesn't exist or has insufficient permissions, create/update it:
-- Drop existing user if necessary (careful!)
DROP USER IF EXISTS 'vicidial'@'localhost';
-- Create new vicidial user with full asterisk database permissions
CREATE USER 'vicidial'@'localhost' IDENTIFIED BY 'vicidial_password_123';
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER,
TRIGGER, CREATE TEMPORARY TABLES, LOCK TABLES,
EXECUTE, CREATE VIEW, SHOW VIEW, CREATE ROUTINE,
ALTER ROUTINE, REFERENCES
ON asterisk.* TO 'vicidial'@'localhost';
-- For remote MySQL servers
CREATE USER 'vicidial'@'192.168.1.50' IDENTIFIED BY 'vicidial_password_123';
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER,
TRIGGER, CREATE TEMPORARY TABLES, LOCK TABLES,
EXECUTE, CREATE VIEW, SHOW VIEW, CREATE ROUTINE,
ALTER ROUTINE, REFERENCES
ON asterisk.* TO 'vicidial'@'192.168.1.50';
-- Apply changes immediately
FLUSH PRIVILEGES;
-- Verify
SHOW GRANTS FOR 'vicidial'@'localhost';
Test User Connectivity
Exit MySQL and test the vicidial user connection:
# Exit MySQL first
exit;
# Test connection with vicidial credentials
mysql -h 127.0.0.1 -u vicidial -p -e "SELECT VERSION();"
# Enter password when prompted
# Test from specific host (if remote)
mysql -h 192.168.1.50 -u vicidial -p asterisk -e "SHOW TABLES LIMIT 5;"
If successful, you'll see:
+---------+
| VERSION |
+---------+
| 5.7.35 |
+---------+
Step 4: Test Database Connectivity from ViciDial Scripts
Use ViciDial's built-in test utilities to verify connectivity:
# Navigate to astguiclient directory
cd /usr/share/astguiclient/
# Test connection using Perl script
perl -e "
use strict;
use DBI;
my \$dsn = 'DBI:mysql:asterisk:127.0.0.1:3306';
my \$user = 'vicidial';
my \$pass = 'vicidial_password_123';
my \$dbh = DBI->connect(\$dsn, \$user, \$pass)
or die 'Connection failed: ' . DBI->errstr;
print \"Connected successfully to MySQL\n\";
print \"Database handle: \$dbh\n\";
my \$sth = \$dbh->prepare('SELECT COUNT(*) FROM vicidial_log');
\$sth->execute();
my (\$count) = \$sth->fetchrow_array();
print \"Rows in vicidial_log: \$count\n\";
\$dbh->disconnect();
"
Using astguiclient Commands
ViciDial provides diagnostic commands:
# Check if astguiclient is running
sudo ps aux | grep astguiclient | grep -v grep
# View astguiclient process with database info
sudo netstat -anp | grep astguiclient
# Read astguiclient logs
sudo tail -100 /var/log/asterisk/astguiclient.log
Verify Database Tables Exist
# Connect and list all ViciDial tables
sudo mysql -u root -p asterisk -e "SHOW TABLES LIKE 'vicidial%';"
Expected output (partial list):
+----------------------------------+
| Tables_in_asterisk (vicidial%) |
+----------------------------------+
| vicidial_agent_log |
| vicidial_campaigns |
| vicidial_carrier_log |
| vicidial_closer_log |
| vicidial_did_log |
| vicidial_inbound_group |
| vicidial_list |
| vicidial_log |
| vicidial_users |
| vicidial_url_log |
+----------------------------------+
If tables are missing, the database structure is corrupted. Rebuild:
# Backup current database
sudo mysqldump -u root -p asterisk > /tmp/asterisk_backup.sql
# Navigate to ViciDial installation
cd /usr/src/astguiclient/
# Check for installation scripts
ls -la | grep -i sql
# Run MySQL initialization (varies by ViciDial version)
# Example for v2.14+
sudo mysql -u root -p < extras/MySQL_tables.sql
Step 5: Check Network and Firewall Connectivity
If using a remote MySQL server, verify network connectivity:
# Ping the MySQL server
ping 192.168.1.50
# Test port connectivity using telnet
telnet 192.168.1.50 3306
# Alternative using nc (netcat)
nc -zv 192.168.1.50 3306
# If successful output:
# Connection to 192.168.1.50 3306 port [tcp/mysql] succeeded!
Check firewall rules (iptables/UFW):
# UFW (Uncomplicated Firewall)
sudo ufw status
sudo ufw allow from 192.168.1.50 to any port 3306
# iptables
sudo iptables -L -n | grep 3306
sudo iptables -A INPUT -p tcp --dport 3306 -j ACCEPT
sudo iptables-save # Make persistent
# Check MySQL skip-networking setting
sudo mysql -u root -p -e "SHOW VARIABLES LIKE 'skip_networking';"
# Should return OFF or 0
Step 6: Resolve Max Connections Issues
If MySQL is throwing "Too many connections" errors:
# Check current max_connections setting
sudo mysql -u root -p -e "SHOW VARIABLES LIKE 'max_connections';"
# Check current connection count
sudo mysql -u root -p -e "SHOW STATUS LIKE 'Threads_connected';"
Increase max_connections in /etc/mysql/mysql.conf.d/mysqld.cnf:
[mysqld]
# Increase from default 151 to accommodate ViciDial
max_connections = 500
# Increase back_log (connections waiting to connect)
back_log = 128
# Set connection idle timeout
wait_timeout = 28800
interactive_timeout = 28800
max_allowed_packet = 64M
Apply the changes:
sudo systemctl restart mysql
# Verify
sudo mysql -u root -p -e "SHOW VARIABLES LIKE 'max_connections';"
Step 7: Fix Configuration File Syntax Errors
Common mistakes in config files:
Incorrect astguiclient.conf
# WRONG - spaces around equals
MYSQLHOST = 127.0.0.1
# CORRECT - no spaces
MYSQLHOST=127.0.0.1
# WRONG - quotes not needed
MYSQLHOST="127.0.0.1"
# CORRECT - no quotes
MYSQLHOST=127.0.0.1
Validate syntax:
# Check for syntax issues
sudo perl -c /usr/share/astguiclient/astguiclient.pl
# If output shows "syntax OK"
# Then test configuration loading
sudo perl -e "require '/etc/astguiclient.conf'; print \"Config loaded\n\";"
Incorrect vicidial_web.conf
// WRONG - missing semicolon
$DBhost = "127.0.0.1"
// CORRECT - with semicolon
$DBhost = "127.0.0.1";
// WRONG - quotes inconsistent
$DBpass = 'my_pass;
// CORRECT - matching quotes
$DBpass = 'my_pass';
Validate PHP syntax:
# Check web config syntax
php -l /var/www/html/vicidial/vicidial_web.conf
# Output should be "No syntax errors detected in..."
Step 8: Restart ViciDial Services
After fixing configuration or MySQL issues, restart ViciDial services:
# Restart Asterisk
sudo systemctl restart asterisk
# Alternative
sudo /usr/sbin/asterisk -rx "core restart now"
# Restart astguiclient
sudo systemctl restart astguiclient
# Restart web interface (Apache)
sudo systemctl restart apache2 # Debian/Ubuntu
sudo systemctl restart httpd # CentOS/RHEL
# Verify all services running
sudo systemctl status asterisk astguiclient apache2
Check for errors immediately after restart:
# Tail Asterisk logs
sudo tail -50 /var/log/asterisk/messages
# Tail astguiclient logs
sudo tail -50 /var/log/asterisk/astguiclient.log
# Check Asterisk console
sudo asterisk -r
# Then in Asterisk CLI:
# > show channels
# > sip show peers
# > exit
Troubleshooting
Issue: Connection works from command line but not from ViciDial
Cause: Config file not being read correctly, permissions issue, or cached connections.
Solution:
# Verify ViciDial config permissions
ls -la /etc/astguiclient.conf
# Should be readable by asterisk user
sudo chmod 644 /etc/astguiclient.conf
# Check which user astguiclient runs as
ps aux | grep astguiclient | grep -v grep
# Ensure that user can read config
sudo chown root:asterisk /etc/astguiclient.conf
# Verify in astguiclient.pl that it's reading config
sudo grep -n "require.*astguiclient.conf" /usr/share/astguiclient/astguiclient.pl
Issue: Intermittent connection failures during peak hours
Cause: Connection pool exhaustion, slow queries, or network timeouts.
Solution:
# Increase wait_timeout to prevent connection drops
sudo mysql -u root -p -e "SET GLOBAL wait_timeout=28800;"
# Verify
sudo mysql -u root -p -e "SHOW VARIABLES LIKE 'wait_timeout';"
# Make persistent in mysqld.cnf
sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf
# Add: wait_timeout = 28800
# Add: max_connections = 1000
# Check for slow queries
sudo tail -100 /var/log/mysql/slow.log
# Enable slow query log if not present
sudo mysql -u root -p << EOF
SET GLOBAL slow_query_log = 'ON';
SET GLOBAL long_query_time = 2;
EOF
Issue: "Lost connection to MySQL server" during calls
Cause: Network interruption, MySQL restart, or connection timeout.
Solution:
# Add connection retry logic to astguiclient.pl
# Edit the DBI->connect call to include retry parameters
sudo nano /usr/share/astguiclient/astguiclient.pl
# Look for DBI->connect and modify to:
my $dbh = DBI->connect(
'DBI:mysql:asterisk:127.0.0.1:3306',
'vicidial',
'password',
{
RaiseError => 1,
AutoCommit => 1,
mysql_auto_reconnect => 1,
mysql_use_result => 1,
Timeout => 10,
}
) or die "Cannot connect: $DBI::errstr";
Issue: MySQL crashes or becomes unresponsive
Cause: Out of memory, disk space full, or InnoDB corruption.
Solution:
# Check available disk space
df -h
# Check MySQL data directory
du -sh /var/lib/mysql/
# Check free memory
free -h
# Increase InnoDB buffer pool in mysqld.cnf
# For systems with 16GB+ RAM:
innodb_buffer_pool_size = 8G
# Check InnoDB status
sudo mysql -u root -p -e "SHOW ENGINE INNODB STATUS\G" | head -100
# If corruption detected, repair tables:
sudo mysql -u root -p -e "REPAIR TABLE vicidial_log;"
sudo mysql -u root -p -e "REPAIR TABLE vicidial_closer_log;"
Issue: Authentication fails with "Access denied"
Cause: Password mismatch, special characters in password, or encoding issues.
Solution:
# Reset vicidial user password
sudo mysql -u root -p << EOF
ALTER USER 'vicidial'@'localhost' IDENTIFIED BY 'new_secure_password_123';
FLUSH PRIVILEGES;
EOF
# Update astguiclient.conf with new password
sudo nano /etc/astguiclient.conf
# Change MYSQLPASS=new_secure_password_123
# Update vicidial_web.conf
sudo nano /var/www/html/vicidial/vicidial_web.conf
# Change $DBpass = 'new_secure_password_123';
# Test connection
mysql -u vicidial -p -h 127.0.0.1 asterisk -e "SELECT 1;"
For special characters in passwords, escape properly:
# Password with special chars: P@ssw0rd!#2024
# In config files - no escaping needed
MYSQLPASS=P@ssw0rd!#2024
# In Perl - use backslashes for special chars
my $pass = 'P@ssw0rd!#2024'; # Fine in single quotes
# In PHP - use backslashes
$DBpass = 'P@ssw0rd!\\#2024'; # Escape # if needed
Issue: Remote MySQL server connection fails (network)
Cause: Firewall blocking, bind-address mismatch, or DNS resolution.
Solution:
# Test MySQL server accessibility
ping 192.168.1.50
telnet 192.168.1.50 3306
nc -zv 192.168.1.50 3306
# Test from ViciDial server with mysql-client
mysql -h 192.168.1.50 -u vicidial -p asterisk -e "SELECT VERSION();"
# On MySQL server - verify bind-address
sudo grep "^bind-address" /etc/mysql/mysql.conf.d/mysqld.cnf
# Update if needed
sudo sed -i 's/bind-address = 127.0.0.1/bind-address = 0.0.0.0/' /etc/mysql/mysql.conf.d/mysqld.cnf
# Restart MySQL
sudo systemctl restart mysql
# Create user for remote access if not present
sudo mysql -u root -p << EOF
CREATE USER 'vicidial'@'192.168.1.X' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON asterisk.* TO 'vicidial'@'192.168.1.X';
FLUSH PRIVILEGES;
EOF
# Test again
mysql -h 192.168.1.50 -u vicidial -p -e "SHOW DATABASES;"
Issue: astguiclient exits with database error
Cause: Config not found, permissions issue, or service dependency.
Solution:
# Check if astguiclient is running
sudo ps aux | grep astguiclient | grep -v grep
# If not, manually start with verbose output
cd /usr/share/astguiclient/
sudo -u asterisk ./astguiclient.pl --verbose
# Check systemd service file
sudo cat /etc/systemd/system/astguiclient.service
# Ensure service waits for MySQL
# Modify service file:
sudo nano /etc/systemd/system/astguiclient.service
# Ensure it includes:
[Unit]
After=mysql.service
Requires=mysql.service
[Service]
User=asterisk
ExecStart=/usr/share/astguiclient/astguiclient.pl
Restart=always
RestartSec=10
# Reload service
sudo systemctl daemon-reload
sudo systemctl restart astguiclient
Advanced: Connection Pooling and Optimization
For large ViciDial installations, implement connection pooling:
Using ProxySQL (Recommended)
# Install ProxySQL
wget https://repo.proxysql.com/ProxySQL/proxysql-2.4.4-centos7.x86_64.rpm
sudo rpm -ivh proxysql-2.4.4-centos7.x86_64.rpm
# Start ProxySQL
sudo systemctl start proxysql
sudo systemctl enable proxysql
Configure ProxySQL admin panel:
# Connect to ProxySQL admin
mysql -u admin -padmin -h 127.0.0.1 -P 6032
# In ProxySQL admin:
INSERT INTO mysql_servers (hostgroup_id, hostname, port, weight)
VALUES (0, '192.168.1.50', 3306, 1000);
INSERT INTO mysql_users (username, password, active, default_hostgroup)
VALUES ('vicidial', 'vicidial_password_123', 1, 0);
# Save configuration
SAVE MYSQL SERVERS TO DISK;
SAVE MYSQL USERS TO DISK;
LOAD MYSQL SERVERS TO RUNTIME;
LOAD MYSQL USERS TO RUNTIME;
Update ViciDial config to use ProxySQL:
# /etc/astguiclient.conf
MYSQLHOST=127.0.0.1
MYSQLPORT=6033 # ProxySQL port instead of 3306
MYSQLLOGIN=vicidial
MYSQLPASS=vicidial_password_123
MYSQLDATABASE=asterisk
Restart ViciDial services:
sudo systemctl restart astguiclient asterisk
Monitoring Connection Health
# View active connections
sudo mysql -u root -p -e "SHOW PROCESSLIST;"
# Kill idle connections if needed
sudo mysql -u root -p -e "KILL <process_id>;"
# Monitor connection usage over time
watch -n 5 'mysql -u root -p -e "SHOW STATUS LIKE \"Threads_connected\";'
# Set up monitoring script
sudo nano /usr/local/bin/mysql_monitor.sh
#!/bin/bash
CONNECTIONS=$(mysql -u root -p -e "SHOW STATUS LIKE 'Threads_connected'" | tail -1 | awk '{print $2}')
MAX_CONN=$(mysql -u root -p -e "SHOW VARIABLES LIKE 'max_connections'" | tail -1 | awk '{print $2}')
USAGE=$((CONNECTIONS * 100 / MAX_CONN))
echo "MySQL Connections: $CONNECTIONS / $MAX_CONN ($USAGE%)"
if [ $USAGE -gt 80 ]; then
echo "WARNING: Connection pool usage above 80%"
# Send alert, restart service, etc.
fi
Summary
ViciDial MySQL connection errors are typically caused by:
- MySQL not running or not listening — Verify service status and bind-address
- Incorrect credentials — Validate user, password, host, and port in config files
- Missing database or tables — Check database structure and rebuild if necessary
- Insufficient user permissions — Grant full asterisk database privileges to vicidial user
- Network/firewall issues — Test connectivity from client to MySQL server
- Configuration syntax errors — Verify proper spacing and quotes in config files
- Connection pool exhaustion — Increase max_connections and implement connection pooling
- Service startup order — Ensure MySQL starts before astguiclient
Recommended diagnostic process:
- Verify MySQL is running:
sudo systemctl status mysql - Test local connectivity:
mysql -u vicidial -p asterisk -e "SHOW TABLES;" - Check config files for syntax and credentials
- Validate user permissions in MySQL
- Test from ViciDial server using Perl test script
- Restart services in order: MySQL → Asterisk → astguiclient
- Monitor logs for errors:
/var/log/asterisk/messagesand/var/log/asterisk/astguiclient.log - Use ProxySQL for connection pooling on high-volume systems
Prevention best practices:
- Monitor MySQL connection count regularly
- Set up automated backups of vicidial database
- Document all MySQL credentials in secure location
- Use identical credentials across all config files
- Implement connection timeout settings to prevent stale connections
- Test MySQL failover procedures in advance
- Monitor disk space for
/var/lib/mysql/partition - Keep MySQL and ViciDial versions updated
- Set up alerts for connection failures or slow queries
By following this comprehensive guide, you'll be able to quickly diagnose and resolve any MySQL connection issues in your ViciDial production environment.