windows下新安裝的mysql修改root password問題


常用步驟:

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: 1

mysql>

4. 從my.ini中去掉之前加入的skip-grant-tables那行, 然后重啟mysql后,就可以用帶password的root登錄了

E:\mysql>net stop mysql
MySQL 服務正在停止.
MySQL 服務已成功停止。


E:\mysql>net start mysql
MySQL 服務正在啟動 .
MySQL 服務已經啟動成功。


E:\mysql>mysql -u root -p
Enter password: ***********
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.15

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>

5. 這個時候還沒完,你還需要在正常模式下再修改一次密碼,否則啥也做不了,如下錯誤:

mysql> use mysql
ERROR 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 mysql
mysql>Database changed

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM