If you install MySQL or MariaDB and are unable to access it locally via root you can try the following:

1. Stop the MySQL or MariaDB service

a) Debain: 'service mysql stop'

b) CentOS: run 'systemctl stop mariadb.service' (mysql.service) 

2. mysql --skip-grant-tables

3.  mysql

4. UPDATE mysql.user SET Grant_priv='Y', Super_priv='Y' WHERE User='root';

5. FLUSH PRIVILEGES;