在ubuntu中重設mysql伺服器root密碼的方法

來源:互聯網
上載者:User

首先停止mysql服務: 複製代碼 代碼如下:root@webserver:/home/webmaster# service mysql stop

接著採用忽略密碼認證模式重新建立一個mysql服務: 複製代碼 代碼如下:root@webserver:/home/webmaster# mysqld --user=mysql --skip-grant-tables --skip-networking &

成功啟動後返回PID及其它啟動資訊 複製代碼 代碼如下:[1] 3591
root@webserver:/home/webmaster# 121005 2:59:27 [Note] Plugin 'FEDERATED' is disabled.
121005 2:59:27 InnoDB: The InnoDB memory heap is disabled
121005 2:59:27 InnoDB: Mutexes and rw_locks use GCC atomic builtins
121005 2:59:27 InnoDB: Compressed tables use zlib 1.2.3.4
121005 2:59:27 InnoDB: Initializing buffer pool, size = 128.0M
121005 2:59:27 InnoDB: Completed initialization of buffer pool
121005 2:59:27 InnoDB: highest supported file format is Barracuda.
121005 2:59:27 InnoDB: Waiting for the background threads to start
121005 2:59:28 InnoDB: 1.1.8 started; log sequence number 1595685
121005 2:59:28 [Note] mysqld: ready for connections.
Version: '5.5.24-0ubuntu0.12.04.1' socket: '/var/run/mysqld/mysqld.sock' port: 0 (Ubuntu)

串連到mysql系統庫: 複製代碼 代碼如下:root@webserver:/home/webmaster# mysql -u root mysql

串連到mysql庫後直接修改root帳號的密碼為新的密碼'mynewpasswd': 複製代碼 代碼如下:Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> update user set Password=PASSWORD('mynewpasswd') where user='root';
Query OK, 3 rows affected (0.00 sec)
Rows matched: 3 Changed: 3 Warnings: 0

mysql> FLUSH PRIVILEGES;
mysql> quit;
Bye

中止mysql服務進程(PID 3591見前面啟動服務時的螢幕資訊): 複製代碼 代碼如下:root@webserver:/home/webmaster# kill 3591

正常啟動 mysql服務,並用新密碼登入mysql伺服器成功: 複製代碼 代碼如下:root@webserver:/home/webmaster#service mysql start
root@webserver:/home/webmaster#mysql -u root -pmynewpasswd

相關文章

聯繫我們

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