如何在Ubuntu 18.04 Linux上重置root mariadb密码

让我们首先停止当前运行的MariaDB数据库:

$ sudo service mariadb stop

一旦准备好手动启动MariaDB服务器,使用以下Linux命令和命令行选项:

$ sudo /usr/sbin/mysqld --skip-grant-tables --skip-networking &
[1] 3216

确认MariaDB进程按预期运行:

$ jobs
[1]+  Running        sudo /usr/sbin/mysqld --skip-grant-tables --skip-networking &

在此阶段,我们能够在没有密码的情况下访问MariaDB数据库:

$ mysql -u root
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 2
Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]>

使用当前MariaDB会话首次刷新权限:

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

接下来,重置root密码。
以下Linux命令将将MySQL root密码重置为onitroad.com

mysql> update mysql.user set password=password('onitroad.com') where user='root';
Query OK, 0 rows affected, 1 warning (0.00 sec)

退出MariaDB会话:

mysql> quit                                                                                                                                                                                    
Bye

优雅地终止当前的mysqld过程:

$ sudo pkill mysqld                                                                                                                                                        
onitroad@ubuntu:~$ jobs                                                                                                                                                                     
[1]+  Done       sudo /usr/sbin/mysqld --skip-grant-tables --skip-networking

最后,启动MariaDB数据库:

$ sudo service mariadb start

如果一切顺利,我们现在应该能够使用root密码登录MariaDB数据库:

$ sudo mysql -u root --password=onitroad.com
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 3
Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]>
日期:2020-07-07 20:55:36 来源:oir作者:oir