MySQL in Ubuntu Linux - I cannot connect to the server
AppArmor is a Linux kernel security module that allows the system administrator to restrict programs' capabilities with per-program profiles. Have you tried to disable it and see if the connection works?
Check here on how to do that: help.ubuntu.com/community/AppArmor#Disable_AppArmor_framework
Another idea you can check with ss -tnl if you can see localhost:3306 on listening mode, if ss is not available use netstat -tnl
$ man ss
ss - another utility to investigate sockets
-t, --tcp
    Display TCP sockets.

-n, --numeric
    Do not try to resolve service names. Show exact bandwidth values, instead of human-readable.

l, --listening
    Display only listening sockets (these are omitted by default).


# Usually something like that means you have the service listening on 
# localhost port 3306 in that case the port you configured your mysql to be running
State   Recv-Q   Send-Q     Local Address:Port      Peer Address:Port  Process  
LISTEN  0        4096           127.0.0.1:3306          0.0.0.0:*