mysql忘記root密碼

來源:互聯網
上載者:User

標籤:NPU   admin   table   database   error   root   user   copy   roo   

mysql忘記了超級使用者管理密碼,可以利用重新啟動mysql進程的時候帶 --skip-grant-tables參數來啟動資料庫,並空密碼登入。這個就是相當於是資料庫第一次啟動的時候。隨後可以查看mysql.user表裡面的超級使用者,以及修改超級使用者的密碼

1# 關閉MYSQL instance,或者殺死進程

2# 重新啟動mysql,帶--skip-grant-tables語句

[[email protected] my.cnf.d]$ mysqld_safe --defaults-file=‘/data/mysqldata/3306/my.cnf‘  --skip-grant-tables &[1] 32530[[email protected] my.cnf.d]$ 180828 19:02:13 mysqld_safe Logging to ‘/data/mysqldata/3306/data/../mysql-error.log‘.180828 19:02:13 mysqld_safe Starting mysqld daemon with databases from /data/mysqldata/3306/data[[email protected] my.cnf.d]$ 

3# 空密碼登入MySQL

[[email protected] my.cnf.d]$ msyql -S /data/mysqldata/3306/mysql.sock bash: msyql: command not found...[[email protected] my.cnf.d]$ mysql -S /data/mysqldata/3306/mysql.sock Welcome to the MySQL monitor.  Commands end with ; or \g.Your MySQL connection id is 1Server version: 5.6.31-log Source distributionCopyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.([email protected])[(none)]> 

4# 修改mysql.user表

([email protected])[(none)]> use mysql;Reading table information for completion of table and column namesYou can turn off this feature to get a quicker startup with -ADatabase changed([email protected])[mysql]> ([email protected])[mysql]> select user,host,password from user;+------+-----------+-------------------------------------------+| user | host      | password                                  |+------+-----------+-------------------------------------------+| root | localhost | *A0F874BC7F54EE086FCE60A37CE7887D8B31086B |+------+-----------+-------------------------------------------+1 row in set (0.00 sec)([email protected])[mysql]> update user set password=password(‘password123‘) where user=‘root‘;Query OK, 0 rows affected (0.00 sec)Rows matched: 1  Changed: 0  Warnings: 0([email protected])[mysql]> 

5# 正常關閉資料庫

[[email protected] my.cnf.d]$ mysqladmin -S /data/mysqldata/3306/mysql.sock -uroot -p‘password123‘ shutdownWarning: Using a password on the command line interface can be insecure.180828 19:04:54 mysqld_safe mysqld from pid file /data/mysqldata/3306/mysql.pid ended[1]+  Done                    mysqld_safe --defaults-file=‘/data/mysqldata/3306/my.cnf‘ --skip-grant-tables[[email protected] my.cnf.d]$ 

6# 正常開啟資料庫

[[email protected] my.cnf.d]$ mysqld_safe --defaults-file=‘/data/mysqldata/3306/my.cnf‘  &[1] 33094[[email protected] my.cnf.d]$ 180828 19:05:04 mysqld_safe Logging to ‘/data/mysqldata/3306/data/../mysql-error.log‘.180828 19:05:04 mysqld_safe Starting mysqld daemon with databases from /data/mysqldata/3306/data[[email protected] my.cnf.d]$

7# 正常登入資料庫

[[email protected] my.cnf.d]$ mysql -uroot -S ‘/data/mysqldata/3306/mysql.sock‘ -p‘password123‘Warning: Using a password on the command line interface can be insecure.Welcome to the MySQL monitor.  Commands end with ; or \g.Your MySQL connection id is 1Server version: 5.6.31-log Source distributionCopyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.([email protected])[(none)]> 

至此mysql的root密碼修改完成

mysql忘記root密碼

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.