国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 數據庫 > MySQL > 正文

淺談mysql密碼遺忘和登陸報錯的問題

2024-07-24 12:52:10
字體:
來源:轉載
供稿:網友

mysql登錄密碼忘記,其實解決辦法很簡單,只需要在mysql的主配置文件my.cnf里添加一行“跳過授權表”的參數選擇即可!

在my.cnf中添加下面一行:

[root@test-huanqiu ~]# vim /etc/my.cnf              //在[mysqld]區域里添加
........
skip-grant-tables                       //跳過授權表

然后重啟mysql服務,即可無密碼登錄

[root@test-huanqiu ~]# /etc/init.d/mysqld restart

登錄后重置密碼

[root@test-huanqiu ~]# mysql mysql> select host,user,password from mysql.user;+--------------------+------+-------------------------------------------+| host | user | password |+--------------------+------+-------------------------------------------+| localhost | root | *481ACA1BD6D1E86221244904E9C0FABA33B40B84 || host-192-168-1-117 | root | || 127.0.0.1 | root | || ::1 | root | || localhost | | || host-192-168-1-117 | | |+--------------------+------+-------------------------------------------+6 rows in set (0.00 sec)mysql> update mysql.user set password=password("123456") where host="localhost" and user="root";Query OK, 1 row affected (0.02 sec)Rows matched: 1 Changed: 1 Warnings: 0mysql> flush privileges;Query OK, 0 rows affected (0.01 sec)mysql> select host,user,password from mysql.user;+--------------------+------+-------------------------------------------+| host | user | password |+--------------------+------+-------------------------------------------+| localhost | root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 || host-192-168-1-117 | root | || 127.0.0.1 | root | || ::1 | root | || localhost | | || host-192-168-1-117 | | |+--------------------+------+-------------------------------------------+6 rows in set (0.00 sec)mysql>

再次將my.cnf里添加的那一行注釋,然后重啟mysql

[root@test-huanqiu ~]# vim /etc/my.cnf
........
#skip-grant-tables

[root@test-huanqiu ~]# /etc/init.d/mysqld restart

[root@test-huanqiu ~]# mysql -p123456
mysql>

-----------------------------------------------------------------------------------------------------------------------

發現的一個坑:

mysql之前進行了全量備份,在恢復后,發現用之前的密碼登陸不進去了!

使用上面的方法,無密碼登陸后再重置密碼,但是重置密碼后發現仍然登陸不進去。

最后發現是因為mysql.user表內容被清空了!

mysql> select host,user,password from user;
Empty set (0.00 sec)

解決:

插入數據,再重置密碼

mysql> insert into user(host,user,password) values("localhost","root","123456");Query OK, 1 row affected, 3 warnings (0.01 sec)mysql> select host,user,password from user;+-----------+------+----------+| host | user | password |+-----------+------+----------+| localhost | root | 123456 |+-----------+------+----------+1 row in set (0.00 sec)mysql> update mysql.user set password=password("123456") where host="localhost" and user="root";Query OK, 1 row affected (0.01 sec)Rows matched: 1 Changed: 1 Warnings: 0mysql> select host,user,password from user;+-----------+------+-------------------------------------------+| host | user | password |+-----------+------+-------------------------------------------+| localhost | root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |+-----------+------+-------------------------------------------+1 row in set (0.00 sec)mysql> insert into user(host,user,password) values("127.0.0.1","root","123456");Query OK, 1 row affected, 3 warnings (0.00 sec)mysql> select host,user,password from user;+-----------+------+-------------------------------------------+| host | user | password |+-----------+------+-------------------------------------------+| localhost | root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 || 127.0.0.1 | root | 123456 |+-----------+------+-------------------------------------------+2 rows in set (0.00 sec)mysql> update mysql.user set password=password("123456") where user="root";Query OK, 1 row affected (0.00 sec)Rows matched: 2 Changed: 1 Warnings: 0mysql> select host,user,password from user;+-----------+------+-------------------------------------------+| host | user | password |+-----------+------+-------------------------------------------+| localhost | root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 || 127.0.0.1 | root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |+-----------+------+-------------------------------------------+
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 四川省| 弋阳县| 三江| 涿鹿县| 惠来县| 忻州市| 墨竹工卡县| 吴桥县| 青河县| 仪陇县| 津南区| 晋州市| 当涂县| 壤塘县| 荔波县| 灵武市| 曲沃县| 临沭县| 白河县| 鄂温| 大安市| 尼木县| 舒兰市| 宝兴县| 永济市| 平舆县| 万盛区| 沙田区| 繁峙县| 同德县| 吉林省| 永和县| 瑞丽市| 通江县| 铜山县| 扎囊县| 古浪县| 靖宇县| 门源| 梁河县| 延长县|