Ubuntu 忘記 phpMyAdmin 登入密碼

amouks發表於2020-12-02

Ubuntu 忘記 phpMyAdmin 登入密碼

關於phpMyAdmin

phpMyAdmin is a free software tool written in PHP, intended to handle the administration of MySQL over the Web. phpMyAdmin supports a wide range of operations on MySQL and MariaDB. Frequently used operations (managing databases, tables, columns, relations, indexes, users, permissions, etc) can be performed via the user interface, while you still have the ability to directly execute any SQL statement.

0X00 找到my.cnf檔案

登入ubuntu系統,找到檔案:my.cnf,一般來說檔案的位置為:/etc/mysql/my.cnf,如不存在,建議在系統直接查詢locate my.cnf | grep cnf

root@ubuntu:/# locate my.cnf | grep cnf
/etc/mysql/my.cnf

0x01 跳過

使用vim /etc/mysql/my.cnf[mysqld]目錄下加上一句skip-grant-tables,使用鍵盤ESC退出,然後輸入wq儲存!

[mysqld]
#
# * Basic Settings
#
skip-grant-tables 
user            = mysql
pid-file        = /var/run/mysqld/mysqld.pid
socket          = /var/run/mysqld/mysqld.sock
port            = 3306
basedir         = /usr
datadir         = /var/lib/mysql
tmpdir          = /tmp
lc-messages-dir = /usr/share/mysql
skip-external-locking

0x02 重啟

使用命令 service mysql restart重啟mysql服務

root@ubuntu:/# service mysql  restart
mysql stop/waiting
mysql start/running, process 3978

0x03 設定賬號密碼

輸入mysql進入,重新設定賬號密碼update mysql.user set password=password('jidd@u123.') where user='root';之後在重新整理許可權flush privileges

root@ubuntu:/# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 38
Server version: 5.5.54-0ubuntu0.12.04.1 (Ubuntu)

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

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

mysql>

我這裡設定密碼為jidd@u123.

mysql> update mysql.user set password=password('jidd@u123.') where user='root';
Query OK, 4 rows affected (0.00 sec)
Rows matched: 4  Changed: 4  Warnings: 0

重新整理許可權

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

0x04 實現正常登入

終端實現正常登入

root@ubuntu:/# mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 38
Server version: 5.5.54-0ubuntu0.12.04.1 (Ubuntu)

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

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

web頁面的登入
為

0X05 完成密碼修改

最後不要忘記重複使用vim /etc/mysql/my.cnf[mysqld]目錄下注釋掉:#skip-grant-tables,使用鍵盤ESC退出,輸入wq儲存!然後重啟service mysql restart,希望能夠幫到你解決問題。

相關文章