I just installed MariaDB 10.1.29 on Ubuntu 18.04. From the command line I can connect using sudo:
sudo mysql -u root -p
But not without sudo.
As it turns out, this is expected behaviour for MariaDB and MySQL. To overcome the issue, it is advisable to create a separate user and grant access to all databases created. Here is a step by step guide on how to create databases using the command line and grant permissions to the user of your choice.
$ sudo mysql -u root -p
mysql> CREATE DATABASE `database_name`;
mysql> CREATE USER 'user_name' IDENTIFIED BY 'a_secure_password';
mysql> GRANT ALL PRIVILEGES ON database_name.* TO 'user_name'@'%' WITH GRANT OPTION;
mysql> FLUSH PRIVILEGES;