MySQL5.7.24 忘記root密碼重設方法
在Linux下安裝了SQL/">MySQL5.7.24,重新設定密碼的時候竟然忘記root密碼了,沒辦法,只能重新搞一下,親測可用。
此處我用的是MySQL5.7.24的方法,其他版本的MySQL用這個方法或許不一樣。
首先結束當前正在執行的mysql程序
linuxidc@linuxidc:~$ sudo /etc/init.d/mysql stop
[ ok ] Stopping mysql (via systemctl): mysql.service.
用mysql安全模式執行並跳過許可權驗證
linuxidc@linuxidc:~$ sudo mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
[1] 22024
linuxidc@linuxidc:~$ 2018-11-01T08:39:38.987953Z mysqld_safe Logging to syslog.
2018-11-01T08:39:38.992011Z mysqld_safe Logging to '/var/log/mysql/error.log'.
2018-11-01T08:39:39.012604Z mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
用空密碼方式使用root使用者登入 MySQL
linuxidc@linuxidc:~$ sudo mysql -u root mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.24-0Ubuntu0.18.04.1 (Ubuntu)
Copyright (c) 2000, 2018,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> update user set Password = PASSWORD('root') where User ='root';
ERROR 1054 (42S22): Unknown column 'Password' in 'field list'
執行後報錯 ERROR 1054(42S22) Unknown column 'password' in ‘field list’
錯誤的原因是MySQL 5.7版本下的mysql資料庫下已經沒有password這個欄位了,password欄位改成了authentication_string
所以請使用一下命令:
mysql> use mysql;
Database changed
mysql> select User from user; #此處為查詢使用者命令
+------------------+
| User |
+------------------+
| debian-sys-maint |
| mysql.session |
| mysql.sys |
| root |
+------------------+
4 rows in set (0.00 sec)
mysql> update mysql.user set authentication_string=password('root') where user='root'; #修改密碼成功
Query OK, 1 row affected, 1 warning (0.11 sec)
Rows matched: 1 Changed: 1 Warnings: 1
mysql> flush privileges; #重新整理許可權立即生效
Query OK, 0 rows affected (0.05 sec)
退出
mysql> quit
Bye
Linux公社的RSS地址 : ofollow,noindex" target="_blank">https://www.linuxidc.com/rssFeed.aspx
本文永久更新連結地址: https://www.linuxidc.com/Linux/2018-11/155125.htm