如何重設mysql的密碼

來源:互聯網
上載者:User

標籤:

  1. 如何重設mysql的密碼  
  2.   
  3. 如果知道密碼,則通過以下方式修改;  
  4.   
  5.     [email protected]:~$ mysql --user=root --pass mysql  
  6.     Enter password:  
  7.        
  8.     mysql> update user set Password=PASSWORD(‘new-password-here‘) WHERE User=‘root‘;  
  9.     Query OK, 2 rows affected (0.04 sec)  
  10.     Rows matched: 2  Changed: 2  Warnings: 0  
  11.        
  12.     mysql> flush privileges;  
  13.     Query OK, 0 rows affected (0.02 sec)  
  14.        
  15.     mysql> exit  
  16.     Bye  
  17.       
  18. 如果忘記密碼,則先停止mysql,然後加上參數skip-grant-tables重新啟動mysql server  
  19.   
  20.     [email protected]:~# /etc/init.d/mysql stop  
  21.        
  22.     Now you should start up the database in the background, via the mysqld_safe command:  
  23.        
  24.     [email protected]:~# /usr/bin/mysqld_safe --skip-grant-tables &  
  25.     [1] 4271  
  26.     Starting mysqld daemon with databases from /var/lib/mysql  
  27.     mysqld_safe[6763]: started  
  28.       
  29. 然後登陸mysql,修改密碼  
  30.   
  31.     [email protected]:~$ mysql --user=root mysql  
  32.     Enter password:  
  33.        
  34.     mysql> update user set Password=PASSWORD(‘new-password-here‘) WHERE User=‘root‘;  
  35.     Query OK, 2 rows affected (0.04 sec)  
  36.     Rows matched: 2  Changed: 2  Warnings: 0  
  37.        
  38.     mysql> flush privileges;  
  39.     Query OK, 0 rows affected (0.02 sec)  
  40.        
  41.     mysql> exit  
  42.     Bye  
  43.   
  44. 最後重啟mysql server就可以了。  
  45.   
  46.     [email protected]:~# /etc/init.d/mysql start  
  47.     Starting MySQL database server: mysqld.  
  48.     Checking for corrupt, not cleanly closed and upgrade needing tables..  
  49.       
  50. 用新密碼登陸驗證下  
  51.   
  52.     [email protected]:~# mysql --user=root --pass=new-password-here  
  53.     Welcome to the MySQL monitor.  Commands end with ; or \g.  
  54.     Your MySQL connection id is 5 to server version: 5.0.24a-Debian_4-log  
  55.        
  56.     Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the buffer.  
  57.        
  58.     mysql> exit  
  59.     Bye  

如何重設mysql的密碼

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.