MariaDB忘记root密码

在mariadb的配置文件中加入下列一行

vim /etc/my.conf.d/server.cnf
[mysqld]
skip-grant-tables  # 加入此行

重启mariadb服务

systemctl start mariadb.service

登录mysql

[root@vps]# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 8
Server version: 10.3.21-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.


MariaDB [mysql]> use mysql
MariaDB [mysql]> update user set password=password('123456') where User='root';
Query OK, 4 rows affected (0.001 sec)
Rows matched: 5  Changed: 4  Warnings: 0

MariaDB [mysql]> flush privileges;
Query OK, 0 rows affected (0.000 sec)

MariaDB [mysql]> exit
Bye

还原配置文件
重启服务再次登录

[root@tx_sh_vps wordpress]# systemctl restart mariadb.service 
[root@tx_sh_vps wordpress]# mysql -uroot -p 
Enter password: 

你可能感兴趣的:(mysql,mysql)