在Linux環境下mysql的root密碼忘記解決方案

來源:互聯網
上載者:User

標籤:修改密碼   伺服器   資料庫   linux   mysql   

                                           

mysql版本不同,修改密碼的方法大同小異,但是有一定的區別:

mysql5.1
 

1.首先確認伺服器出於安全的狀態,也就是沒有人能夠任意地串連MySQL資料庫。

2.修改MySQL的登入設定:
# vi /etc/my.cnf
在[mysqld]的段中加上一句:skip-grant-tables 儲存並且退出

3.重新啟動mysqld service mysqld restart

4.登入並修改MySQL的root密碼

mysql> USE mysql ;
mysql> UPDATE user SET Password = password ( ‘new-password‘ ) WHERE User = ‘root‘ ;
mysql> flush privileges ;
mysql> quit

5.將MySQL的登入設定修改回來
# vi /etc/my.cnf
將剛才在[mysqld]的段中加上的skip-grant-tables刪除

6.重新啟動mysqld
# /etc/init.d/mysqld restart   ( service mysqld restart )

mysql5.7
1.停掉資料庫: service mysql stop
2.運行:
# mysqld_safe --skip-grant-tables &
3.登陸資料庫: mysql -p

4.更改密碼
: 
mysql> update mysql.user set authentication_string=password(‘123qwe‘) where user=‘root‘ and Host = ‘localhost‘;
不過這裡要提示一下:新版本的資料庫下的user表裡面已經沒有password了
而是將加密後的使用者密碼儲存在authentication_string欄位下面
flush privileges;
quit
5. 重啟下mysql : service mysql restart
 

但此時操作似乎功能不完全,還要alter user…

mysql> alter user ‘root‘@localhost‘ identified by ‘123456‘


本文出自 “辛舒展” 部落格,請務必保留此出處http://xinsz08.blog.51cto.com/10565212/1859063

在Linux環境下mysql的root密碼忘記解決方案

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.