步骤 1 - 检查数据库服务器的版本

[jack@onitroad ~]# mysql --version
mysql  Ver 15.1 Distrib 5.5.52-MariaDB, for Linux (x86_64) using readline 5.1

步骤 3 - 重置root密码

手动启动跳过授权表并在后台跳过网络

[jack@onitroad ~]# sudo mysqld_safe --skip-grant-tables --skip-networking &

登录mysql

[jack@onitroad ~]# mysql -u root
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.52-MariaDB MariaDB Server
Copyright (c) 2000, 2014, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

使用以下命令重置root密码

MariaDB [(none)]> update mysql.user set password=password('MyNewPass') where user='root';
Query OK, 3 rows affected (0.00 sec)
Rows matched: 3  Changed: 3  Warnings: 0
MariaDB [(none)]> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> exit

安全地停止 mysqld_safe

[jack@onitroad ~]# mysqladmin shutdown

启动数据库服务器

[jack@onitroad ~]# systemctl start mariadb  # FOR MARIADB
[jack@onitroad ~]# systemctl start mysql # FOR MYSQL

步骤 2 - 停止数据库服务器

[jack@onitroad ~]# sudo systemctl stop mariadb # FOR MARIADB
[jack@onitroad ~]# sudo systemctl stop mysql # FOR MYSQL
如何在 CentOS 7/RHEL 7 上重置 MySQL 或者 MariaDB Root 密码

在本教程中,我们将介绍如何在 CentOS 7/RHEL 7 上重置 MySQL 和 MariaDB 的 root 密码

日期:2020-06-02 22:17:38 来源:oir作者:oir