實用小技巧! 修改MySQL密碼
如果忘記密碼無法登入資料庫
root@localhost ~]# mysql -uroot -p //密碼輸入錯誤,無法登入
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
解決方案
```sql
[root@localhost ~]# vi /etc/my.cnf //修改配置
[mysqld]
……省略部分
skip-grant-tables //插入空授權登入配置
[root@localhost ~]# systemctl restart mysqld //重啟MySQL
[root@localhost ~]# mysql -uroot -p
Enter password: //直接回車,登入成功
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.20 Source distribution
……省略部分
mysql>
mysql> desc mysql.user; //檢視錶結構,找到密碼存放欄位,5.0版本在authentication_string欄位中
+------------------------+-----------------------------------+------+-----+-----------------------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------------------+-----------------------------------+------+-----+-----------------------+-------+
| Host | char(60) | NO | PRI | | |
| User | char(32) | NO | PRI | | |
| Select_priv | enum('N','Y') | NO | | N | |
| Insert_priv | enum('N','Y') | NO | | N | |
| Update_priv | enum('N','Y') | NO | | N | |
| Delete_priv | enum('N','Y') | NO | | N | |
| Create_priv | enum('N','Y') | NO | | N | |
| Drop_priv | enum('N','Y') | NO | | N | |
| Reload_priv | enum('N','Y') | NO | | N | |
| Shutdown_priv | enum('N','Y') | NO | | N
| Process_priv | enum('N','Y') | NO | | N | |
| File_priv | enum('N','Y') | NO | | N | |
| Grant_priv | enum('N','Y') | NO | | N | |
| References_priv | enum('N','Y') | NO | | N | |
| Index_priv | enum('N','Y') | NO | | N | |
| Alter_priv | enum('N','Y') | NO | | N | |
| Show_db_priv | enum('N','Y') | NO | | N | |
| Super_priv | enum('N','Y') | NO | | N | |
| Create_tmp_table_priv | enum('N','Y') | NO | | N | |
| Lock_tables_priv | enum('N','Y') | NO | | N | |
| Execute_priv | enum('N','Y') | NO | | N | |
| Repl_slave_priv | enum('N','Y') | NO | | N | |
| Repl_client_priv | enum('N','Y') | NO | | N | |
| Create_view_priv | enum('N','Y') | NO | | N | |
| Show_view_priv | enum('N','Y') | NO | | N | |
| Create_routine_priv | enum('N','Y') | NO | | N | |
| Alter_routine_priv | enum('N','Y') | NO | | N | |
| Create_user_priv | enum('N','Y') | NO | | N | |
| Event_priv | enum('N','Y') | NO | | N | |
| Trigger_priv | enum('N','Y') | NO | | N | |
| Create_tablespace_priv | enum('N','Y') | NO | | N | |
| ssl_type | enum('','ANY','X509','SPECIFIED') | NO | | | |
| ssl_cipher | blob | NO | | NULL | |
| x509_issuer | blob | NO | | NULL | |
| x509_subject | blob | NO | | NULL | |
| max_questions | int(11) unsigned | NO | | 0 | |
| max_updates | int(11) unsigned | NO | | 0 | |
| max_connections | int(11) unsigned | NO | | 0 | |
| max_user_connections | int(11) unsigned | NO | | 0 | |
| plugin | char(64) | NO | | mysql_native_password | |
| authentication_string | text | YES | | NULL | |
| password_expired | enum('N','Y') | NO | | N | |
| password_last_changed | timestamp | YES | | NULL | |
| password_lifetime | smallint(5) unsigned | YES | | NULL
| account_locked | enum('N','Y') | NO | | N | |
+------------------------+-----------------------------------+------+-----+-----------------------+-------+
45 rows in set (0.00 sec)
mysql> select host,user,authentication_string from mysql.user; //檢視host,user,authentication_string上欄位的資料
+-----------+---------------+-------------------------------------------+
| host | user | authentication_string |
+-----------+---------------+-------------------------------------------+
| localhost | root | *6691484EA6B50DDDE1926A220DA01FA9E575C18A |
| localhost | mysql.session | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |
| localhost | mysql.sys | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |
| % | myadm | *01A6717B58FF5C7EAFFF6CB7C96F7428EA65FE4C |
| localhost | myadm | *01A6717B58FF5C7EAFFF6CB7C96F7428EA65FE4C |
| % | bbs | *6691484EA6B50DDDE1926A220DA01FA9E575C18A |
| localhost | bbs | *6691484EA6B50DDDE1926A220DA01FA9E575C18A |
| localhost | ltp_admin | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
+-----------+---------------+-------------------------------------------+
8 rows in set (0.00 sec)
mysql> select host,user,authentication_string from mysql.user where user='root' and host='localhost'; //精準過濾出root使用者的密碼欄位
+-----------+------+-------------------------------------------+
| host | user | authentication_string |
+-----------+------+-------------------------------------------+
| localhost | root | *6691484EA6B50DDDE1926A220DA01FA9E575C18A |
+-----------+------+-------------------------------------------+
1 row in set (0.00 sec)
mysql> update mysql.user set authentication_string=null where user='root' and host='localhost';
Query OK, 1 row affected (0.01 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> select host,user,authentication_string from mysql.user where user='root' and host='localhost';
+-----------+------+-----------------------+
| host | user | authentication_string |
+-----------+------+-----------------------+
| localhost | root | NULL |
+-----------+------+-----------------------+
1 row in set (0.00 sec)
mysql> \q
Bye
[root@localhost ~]# vi /etc/my.cnf //修改配置
[mysqld]
……省略部分
# skip-grant-tables //將這條免密登入註釋掉
[root@localhost ~]# systemctl restart mysqld //重啟生效配置
[root@localhost ~]# mysql -uroot -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
[root@localhost ~]# mysql -uroot -p
Enter password: //已經是空密碼狀態了,直接回車登入
Welcome to the MySQL monitor. Commands end with ; or \g.
……省略部分
mysql>
mysql> \q //退出MySQL ,可以重新設定密碼了
Bye
[root@localhost ~]# mysqladmin -u root -p password '123456' //重新設定密碼
Enter password:
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.
[root@localhost ~]# mysql -uroot -p //驗證,使用新密碼登入成功
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
……省略部分
mysql>
相關文章
- 修改 MySQL 登入密碼MySql密碼
- mysql8.0修改密碼MySql密碼
- 修改docker中Mysql的密碼DockerMySql密碼
- 修改Mysql root密碼的方法MySql密碼
- 每天一個實用小技巧!教你在Mac上共享WiFi密碼MacWiFi密碼
- mysql 8.0.11 以上版本修改root密碼MySql密碼
- MySQL 8.0之後版本密碼修改MySql密碼
- 在Linux中修改MySQL的密碼LinuxMySql密碼
- ubuntu安裝mysql後修改密碼UbuntuMySql密碼
- MySQL修改密碼方法總結YRMySql密碼
- 修改MySQL密碼的四種方法MySql密碼
- MYSQL5.7 ROOT密碼修改教程MySql密碼
- MySQL修改賬號密碼方法大全MySql密碼
- ubuntu系統下mysql重置密碼和修改密碼操作UbuntuMySql密碼
- MySQL8.0 忘記 root 密碼下如何修改密碼MySql密碼
- 怎麼修改mysql的連線密碼MySql密碼
- 介紹Linux小技巧,如何實現免密碼登入Linux密碼
- Tomcat 實用小技巧Tomcat
- mysql8.0+修改使用者密碼MySql密碼
- 安裝MySQL8.0.x並修改密碼MySql密碼
- mysql如何修改root使用者的密碼MySql密碼
- Mysql修改密碼之後,Navicat依然使用舊密碼連線問題MySql密碼
- 【實用小技巧】idea程式碼格式美化快捷鍵Idea
- ansible 修改密碼密碼
- Ubuntu 修改密碼Ubuntu密碼
- 公司網站密碼怎麼修改?修改密碼網站?網站密碼
- MYSQL 修改ROOT密碼的常規方式與暴力方式MySql密碼
- 自定義View實用小技巧View
- chpasswd 批量修改密碼密碼
- Mendix 修改pg密碼密碼
- flask框架如何實現修改密碼和免密登入功能Flask框架密碼
- 1、Windows下安裝mysql-8.0.12及修改初始密碼WindowsMySql密碼
- mysql-8.0.16-winx64/Linux修改root使用者密碼MySqlLinux密碼
- 直播開發app,MySQL8修改root密碼加密方式APPMySql密碼加密
- 修改帝國網站登入密碼?網站被人修改了密碼?網站密碼
- Python五種實用的小技巧Python
- Mysql中的小技巧MySql
- 每天一個實用小技巧!歸納多個檔案、批次修改檔名