This is normal if, when you say "access to the database through mysql -u root -p works fine", you mean that you start it as a system root (or under sudo ). You should not do this as a regular user.
Packages created by Ubuntu by default have unix_socket authentication for the local root. To check, run
SELECT user, host, plugin FROM mysql.user;
You should see unix_socket in the plugin column for root@localhost .
If you want to use password authentication, run
UPDATE mysql.user SET plugin = '' WHERE plugin = 'unix_socket'; FLUSH PRIVILEGES;
source share