Mariadb10.3數據庫強制修改ROOT密碼

前提要求:擁有操作系統ROOT權限

目錄

一、測試環境

1.1、系統版本

1.2、軟件版本

二、直接開車

2.1、思路

2.2、密碼修改

2.2.1、停止數據庫服務

2.2.2、啓動特權模式

2.2.3、登錄數據庫

2.2.4、選擇mysql數據庫 

2.2.5、更新root密碼

2.2.6、刷新權限並退出登錄

2.3、操作記錄

2.4、啓動正常模式


一、測試環境

1.1、系統版本

[root@3a5582579588 /]# cat /etc/os-release 
NAME="CentOS Linux"
VERSION="8 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="8"
PLATFORM_ID="platform:el8"
PRETTY_NAME="CentOS Linux 8 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:8"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"

CENTOS_MANTISBT_PROJECT="CentOS-8"
CENTOS_MANTISBT_PROJECT_VERSION="8"
REDHAT_SUPPORT_PRODUCT="centos"
REDHAT_SUPPORT_PRODUCT_VERSION="8"

1.2、軟件版本

Server version: 10.3.17-MariaDB MariaDB Server

二、直接開車

2.1、思路

在MariaDB/MySQL中,官方保留了一個特權模式,本文的方法就是通過這個官方的特權模式進行曲線修改密碼

2.2、密碼修改

2.2.1、停止數據庫服務

[root@3a5582579588 /]# systemctl stop mariadb
[root@3a5582579588 /]# ps -ef | grep mariadb
root      2653   384  0 15:27 pts/1    00:00:00 grep --color=auto mariadb
[root@3a5582579588 /]# netstat -ntlp | grep mysqld
[root@3a5582579588 /]# 

停止服務之後,需要通過ps查看是否保留相關進程,然後使用netstat命令查看端口占用情況,從上面的反饋信息來看,mariadb服務已經被殺的一乾二淨了,這時候就可以使用特權模式進行密碼修改了

2.2.2、啓動特權模式

 mysqld_safe --skip-grant-tables &

執行完成之後就可以直接通過mysql命令登錄數據庫了,依次執行下面的命令即可

2.2.3、登錄數據庫

mysql

2.2.4、選擇mysql數據庫 

use mysql

2.2.5、更新root密碼

update user set password=password('xinyang123') where user='root';

其中xingyang123改爲自己的密碼即可  

 

2.2.6、刷新權限並退出登錄

flush privileges;exit;

2.3、操作記錄

[root@3a5582579588 /]# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 12
Server version: 10.3.17-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 [(none)]> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
MariaDB [mysql]> update user set password=password('xinyang123') where user='root';
Query OK, 0 rows affected (0.000 sec)
Rows matched: 3  Changed: 0  Warnings: 0

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

MariaDB [mysql]> exit;
Bye

2.4、啓動正常模式

2.4.1、停止特權模式

pkill mysqld

2.4.2、啓動服務

systemctl start mariadb

啓動成功之後,嘗試使用特權模式的登錄命令進行登錄,然後發現登錄失敗,說明特權模式已經關閉了

[root@3a5582579588 /]# mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

2.4.3、使用新密碼登錄

此時,新密碼登錄成功,密碼修改完成!!! 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章