Resolving MySQL “Bind on Unix Socket: Permission Denied” Error with Complete Troubleshooting Guide


3 views

When attempting to start MySQL server, you encounter multiple critical errors:

ERROR] Can't open the mysql.plugin table
ERROR] Bind on unix socket: Permission denied
ERROR] Do you already have another mysqld server running?

The system shows no other MySQL processes running (ps ax | grep mysql returns only the grep process), and the socket file (/var/lib/mysql/mysql.sock) keeps disappearing after restart attempts.

First verify these critical components:

# Check MySQL data directory permissions
ls -ld /var/lib/mysql

# Verify mysql.sock file situation
ls -la /var/lib/mysql/mysql.sock

# Confirm port availability
netstat -tulnp | grep 3306

Three potential issues combine to create this problem:

  1. Permission issues with the mysql system user accessing directories
  2. Corrupted system tables (particularly the plugin table)
  3. Filesystem mounting problems with special flags (noatime)

First stop any potential MySQL remnants:

service mysql stop
killall -9 mysqld

Then repair permissions:

chown -R mysql:mysql /var/lib/mysql
chmod -R 755 /var/lib/mysql
chown mysql:mysql /tmp
chmod 1777 /tmp

Force table recovery:

mysqld --skip-grant-tables --skip-networking &
mysql_upgrade --force
service mysql restart

If the issue persists, consider these advanced steps:

# Check SELinux status
sestatus

# Temporary disable SELinux
setenforce 0

# Alternative socket location
[mysqld]
socket=/tmp/mysql.sock

For AppArmor/SELinux related issues:

# Check audit logs
grep mysql /var/log/audit/audit.log | audit2allow

Confirm successful startup with:

mysqladmin -u root -p status
ls -la /var/lib/mysql/mysql.sock

Monitor error logs for residual issues:

tail -f /var/log/mysql/error.log

When encountering the "Bind on unix socket: Permission denied" error in MySQL, it typically indicates a fundamental permission or configuration issue. The key symptoms include:

  • MySQL fails to start with socket binding errors
  • Plugin table appears read-only
  • mysql_upgrade fails due to socket connection issues
  • mysql.sock file gets deleted upon restart

First verify the essential directory permissions:

ls -ld /var/lib/mysql
ls -ld /tmp
ls -la /var/lib/mysql/mysql/plugin.*

The correct ownership should be:

chown -R mysql:mysql /var/lib/mysql
chmod 755 /var/lib/mysql
chmod 1777 /tmp

The missing mysql.sock file is typically created automatically during startup. If it's being deleted, check:

ps aux | grep mysql
netstat -lnp | grep mysql

Modify your my.cnf with these critical socket settings:

[mysqld]
socket=/var/run/mysqld/mysqld.sock

[client]
socket=/var/run/mysqld/mysqld.sock

If the issue persists, try these advanced measures:

  1. Verify SELinux status:
    sestatus
    setenforce 0
  2. Check AppArmor profiles:
    aa-status
    sudo aa-complain /usr/sbin/mysqld
  3. Test with strace for deeper diagnostics:
    strace -f mysqld --user=mysql

For a systematic recovery:

systemctl stop mysql
rm -f /var/lib/mysql/mysql.sock
rm -f /var/run/mysqld/mysqld.pid
mysqld --initialize-insecure --user=mysql
chown -R mysql:mysql /var/lib/mysql
systemctl start mysql
mysql_upgrade -u root

Remember to secure your installation after recovery:

mysql_secure_installation