Sometimes Drupal try to access MySQL using a wrong socket, i.e. /tmp/mysql.sock.
There are two solutions: creating a symbolic link from the wrong location to the right location, or change the php.ini (es. /etc/php.ini) to point to the right socket:
mysqli.default_socket = /var/lib/mysql/mysql.sock
This solution is more reliable, since the symbolic link to socket should be recreated at any system boot on solution #1.