It appears that with recent mariadb, you may log in as root (mysql user) with the client started as root (linux user) but not with the client started as a non-root (linux user). This is documented here:
So in that case, you may log in mysql without problems, but the sudo -u www-data makes owncloud unable to log in as root. You need to create a user with sufficient privileges before.