日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

Linux重置mysql密码

發布時間:2023/12/31 数据库 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Linux重置mysql密码 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

linux數據庫重置密碼的那些事~~


前言

今天打算在RuoYi項目上加一些功能,但是發現我的數據庫又連不上了,密碼之前一樣也不行!!之前記錄的問題的連接也打不開了…想想還是自己重新操作記錄一下吧~

查看root用戶是否存在

mysql> select user,host from user;


如圖所示,如果發現user表中沒有了root用戶,就要再創建用戶角色(自己就是很久沒有使用服務器,再次使用時發現root用戶沒了?具體原因我也還不清楚)
可參考:https://blog.csdn.net/weixin_50419828/article/details/121967191

停掉mysql服務

修改my.conf文件

打開my.cnf文件,修改文件中的skip-grant-tables,去掉#,如果不存在則新加上,這是設置就可以跳過mysql密碼登錄,使用無密登錄然后修改密碼。

vi /etc/my.cnf

無密登錄重置密碼為空

啟動Mysql服務,使用無密登錄,輸入修改密碼語句,刷新權限后退出。
注意:要查看自己mysql的版本,一開始沒有看自己的mysql的版本,自己是8.0的版本,結果看到網上的修改語句直接用就一直報錯…(最好自行百度一下)

mysql8.0版本:update mysql.user set authentication_string=‘123456’ where user=‘root’;

mysql5.7以下版本:UPDATE mysql.user SET Password=PASSWORD(‘123456’) where USER=‘root’;

mysql5.7版本:UPDATE mysql.user SET authentication_string=PASSWORD(‘123456’) where USER=‘root’;

[root@ls ~]# service mysqld start Starting MySQL.. SUCCESS! [root@ls ~]# mysql -u root mysql> update mysql.user set authentication_string='' where user='root'; mysql> flush privileges; mysql> exit;

報錯的語句,提示語法不正確

登錄重置密碼

修改my.cnf文件 注釋掉無密登錄 #skip-grant-tables
重啟mysql服務:service mysql restart
使用mysql -u root -p 登錄mysql
提示輸入密碼直接Enter ,因為我們上一步設置密碼為空了
輸入ALTER USER ‘root’@‘localhost’ IDENTIFIED BY ‘要更換的密碼’;

[root@ls ~]# service mysql restart Redirecting to /bin/systemctl restart mysql.service [root@ls ~]# mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 8 Server version: 8.0.28 MySQL Community Server - GPLCopyright (c) 2000, 2022, Oracle and/or its affiliates.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> use mysql Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '要更換的密碼'; mysql> flush priveleges; mysql> exit;

重啟mysql服務,使用修改后的密碼登錄

設置遠程登陸

mysql> use mysql; mysql> update user set user.Host='%' where user.User='root'; mysql> flush privileges;

使用數據庫客戶端連接試下成功即可~

總結

以上是生活随笔為你收集整理的Linux重置mysql密码的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。