Login to centos server from ssh. Then stop mysqld service and run mysqld_safe with —skip-grant-tables option to be in insecure mode and to reset the password. Then login to mysql server using mysql command without any -u or -p parameter as you are in insecure mode. Then update the root password flush privilage then exit from msyql console. Then use mysqladmin to stop mysql server which will ask for password give recently saved new password. Then finally start the mysqld service.
$ systemctl stop mysqld
$ mysqld_safe --skip-grant-tables &
$ mysql
mysql> UPDATE mysql.user SET Password=PASSWORD('new-password') WHERE User='root';
mysql> FLUSH PRIVILEGES;
mysql> exit;
$ mysqladmin -u root -p shutdown
$ systemctl start mysqld
Edit: ---------------------------------------
$ sudo systemctl stop mariadb
$ sudo mysqld_safe --skip-grant-tables --skip-networking &
$ mysql -u root
MariaDB [(none)]> ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password';
MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> exit;
$ sudo kill `/var/run/mariadb/mariadb.pid`
$ sudo systemctl start mariadb