Linux下MySQL忘記root使用者密碼

來源:互聯網
上載者:User

Linux下MySQL忘記root使用者密碼

今天在接收一台MySQL伺服器的時候發現忘記MySQL的root使用者的密碼,尋找資料發了各種文檔裡面也沒有root使用者密碼,因此需要修改root使用者密碼。

首先確認伺服器出於安全的狀態,也就是沒有人能夠任意地串連MySQL資料庫。因為在重新設定MySQL的root密碼的期間,MySQL資料庫完全出於沒有密碼保護的狀態下,其他的使用者也可以任意地登入和修改MySQL的資訊。最安全的狀態是到伺服器的Console上面操作,並且拔掉網線。

1、修改MySQL的登入設定:
在[mysqld]的段中加上的skip-grant-tables
# sed -i '/mysqld/a\skip-grant-tables ' /etc/my.cnf

2、重新啟動mysqld
# service mysqld restart
Shutting down MySQL. SUCCESS!
Starting MySQL. SUCCESS!

3、登入並修改MySQL的root密碼
# /usr/bin/mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.19 Source distribution

Copyright (c) 2000, 2014, 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.

mysql> 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

mysql> UPDATE user SET Password = password ( 'bkjia' ) WHERE User = 'root' ;
Query OK, 3 rows affected (0.01 sec)
Rows matched: 3  Changed: 3  Warnings: 0
 
mysql> flush privileges ;
Query OK, 0 rows affected (0.01 sec)

mysql> quit
Bye

4、將MySQL的登入設定修改回來
將剛才在[mysqld]的段中加上的skip-grant-tables刪除
# sed -i "/skip-grant-tables/d" /etc/my.cnf

5、重新啟動mysqld
# service mysqld restart
Shutting down MySQL. SUCCESS!
Starting MySQL. SUCCESS!

這個時候,就可以使用root/bkjia進行登入了

Linux下MySQL的root密碼忘記解決方案 

Windows/Linux MySQL忘記root密碼的解決方案

MySQL忘記root密碼解決方案

MySQL 更改root密碼

在Ubuntu中如何重設MySQL伺服器的root密碼

Red Hat 下 MySQL root密碼恢複

本文永久更新連結地址:

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.