I just installed Ubuntu 16.04 and installed web server on it. Everything works well, but I cannot access database. Even if I create new user and grant all privileges, I can\
MySQL makes a difference between "localhost" and "127.0.0.1".
It might be possible that 'root'@'localhost' is not allowed because there is an entry in the user table that will only allow root login from 127.0.0.1.
This could also explain why some application on your server can connect to the database and some not because there are different ways of connecting to the database. And you currently do not allow it through "localhost".
In short, on MariaDB
1) sudo mysql -u root;
2) use mysql;
3) UPDATE mysql.user SET plugin = 'mysql_native_password',
Password = PASSWORD('pass1234') WHERE User = 'root';
4) FLUSH PRIVILEGES;
5) exit;
With mysql Ver 14.14 Distrib 5.7.22 the update statement is now:
update user set authentication_string=password('1111') where user='root';
Users for mysql and for server are 2 different things, look how to add user to database and login with these credentials