PHP Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000] [2002] Connection refused

Well then check if mysql is really not running:

sudo aptitude install nmap

And then:

sudo nmap -sS <ipofdbserverhere>

You can also install the tool on the mysql server, the the command would be:

sudo nmap -sS localhost

In both cases your answer should look like this.

[simmel]@[mars]$ sudo nmap -sS 172.16.1.41

Starting Nmap 6.40 ( http://nmap.org ) at 2015-04-08 15:09 CEST

Nmap scan report for 172.16.1.41
Host is up (0.010s latency).
Not shown: 996 closed ports
PORT     STATE SERVICE
3306/tcp open  mysql

Nmap done: 1 IP address (1 host up) scanned in 33.17 seconds

If it shows you port 3306, it's indeed open and ready for connections. If that is the case use mysql via command line from your computer.

mysql -u<USER> -p<PASSWORD> -h<ipofdbserverhere> <databasename>

The same message appears? Connection refused? Then your user has probably the wrong rights.

Another reason for this is when the mysql server is bound to a certain address, like 127.0.0.1.

To find out check the output from:

sudo netstat -tlpen

If mysql is not listening to 0.0.0.0:3306 but to 127.0.0.1:3306, you only can connect from localhost.

To change that go to /etc/mysql/my.cnf and comment out the following line:

bind-address            = 127.0.0.1

The way to comment it out is to add a leading # character:

#bind-address            = 127.0.0.1

Save the file and restart the mysql service

sudo service mysql restart

Now you should be able to connect.

To change the port, enter, for example:

port = 8888

in /etc/mysql/my.cnf.

Save the file and restart the mysql service:

sudo service mysql restart