標籤:
常用步驟:
1. 在my.ini中的mysqld下添加一行
skip-grant-tables
2.重啟mysql後直接進入後,用SQL直接修改password列:
C:\> net stop mysql
C:\> net start mysql
C:\> mysql
mysql>
mysql> use mysql
Database changed
mysql> UPDATE user SET Password=PASSWORD(‘newpassword‘) where USER=‘root‘;
ERROR 1054 (42S22): Unknown column ‘Password‘ in ‘field list‘
3. 但失敗了,原因是新版的mysql(5.7以後版本)這個列已經改成了"authentication_string", 所以在會失敗,正確的做法是
mysql> UPDATE user SET authentication_string=PASSWORD(‘newpassword‘) where USER=‘root‘;Query OK, 1 row affected, 1 warning (0.00 sec)Rows matched: 1 Changed: 1 Warnings: 1mysql>
4. 從my.ini中去掉之前加入的skip-grant-tables那行, 然後重啟mysql後,就可以用帶password的root登入了
E:\mysql>net stop mysqlMySQL 服務正在停止.MySQL 服務已成功停止。E:\mysql>net start mysqlMySQL 服務正在啟動 .MySQL 服務已經啟動成功。E:\mysql>mysql -u root -pEnter password: ***********Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 2Server version: 5.7.15Copyright (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.mysql>
5. 這個時候還沒完,你還需要在正常模式下再修改一次密碼,否則殺也做了了,如下錯誤:
mysql> use mysqlERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
5. 而且提示很坑爹, 你必須用SET_PASSWORD, 而不是提示所說的ALTER USER
mysql> SET PASSWORD = PASSWORD(‘newpassword‘);Query OK, 0 rows affected, 1 warning (0.00 sec)mysql>use mysqlmysql>Database changed
windows下新安裝的mysql修改root password問題