vim /etc/my.cnf
添加此行
skip-grant-table
systemctl restart mariadb
mysql
select user,password,host from mysql.user;
update mysql.user set password=password(“123456”) where user=“root” and host=“localhost”;
flush privileges;
\q
vim /etc/my.cnf
注释添加的那行
systemctl restart mariadb
登录成功。