update mysql.user set plugin='' where user='root'; flush privileges;
update mysql.user set password=password('yourpasswd') where user='root';
or run mysql_secure_installation from command line and set password.
select user,host,password,plugin from mysql.user; MariaDB [(none)]> select user,host,password,plugin from mysql.user; +------+-----------+-------------------------------------------+--------+ | user | host | password | plugin | +------+-----------+-------------------------------------------+--------+ | root | localhost | *C3F43AFF2CF6AACD60EE1AAB1B48ADB3066E0EA4 | | +------+-----------+-------------------------------------------+--------+
This will disable unix socket authentication as well as set the password to 'root':
~# mysql -u root -e "ALTER USER 'root'@'localhost' IDENTIFIED VIA mysql_native_password USING PASSWORD ('root');"
MariaDB [(NONE)]> SHOW CREATE USER root@localhost; +---------------------------------------------------------------------------------------------------+ | CREATE USER FOR root@localhost | +---------------------------------------------------------------------------------------------------+ | CREATE USER `root`@`localhost` IDENTIFIED BY PASSWORD '*81F5E21E35407D884A6CD4A731AEBFB6AF209E1B' | +---------------------------------------------------------------------------------------------------+ 1 ROW IN SET (0.001 sec)