在ubuntu中重置mysql服務(wù)器root密碼的方法
更新時(shí)間:2012年10月12日 01:12:33 作者:
在ubuntu下安裝了mysql 5 server,結(jié)果不知道什么原因,安裝時(shí)輸入的root帳號(hào)密碼在使用時(shí)無(wú)論如何都不能通過(guò)數(shù)據(jù)庫(kù)服務(wù)器的驗(yàn)證。無(wú)奈只有重置mysql的root帳號(hào)密碼。查了一下,用了以下方法成功的重置了root帳號(hào)密碼
首先停止mysql服務(wù):
root@webserver:/home/webmaster# service mysql stop
接著采用忽略密碼認(rèn)證模式重新創(chuàng)建一個(gè)mysql服務(wù):
root@webserver:/home/webmaster# mysqld --user=mysql --skip-grant-tables --skip-networking &
成功啟動(dòng)后返回PID及其它啟動(dòng)信息
[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系統(tǒng)庫(kù):
root@webserver:/home/webmaster# mysql -u root mysql
連接到mysql庫(kù)后直接修改root帳號(hào)的密碼為新的密碼'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服務(wù)進(jìn)程(PID 3591見(jiàn)前面啟動(dòng)服務(wù)時(shí)的屏幕信息):
root@webserver:/home/webmaster# kill 3591
正常啟動(dòng) mysql服務(wù),并用新密碼登錄mysql服務(wù)器成功:
root@webserver:/home/webmaster#service mysql start
root@webserver:/home/webmaster#mysql -u root -pmynewpasswd
復(fù)制代碼 代碼如下:
root@webserver:/home/webmaster# service mysql stop
接著采用忽略密碼認(rèn)證模式重新創(chuàng)建一個(gè)mysql服務(wù):
復(fù)制代碼 代碼如下:
root@webserver:/home/webmaster# mysqld --user=mysql --skip-grant-tables --skip-networking &
成功啟動(dòng)后返回PID及其它啟動(dòng)信息
復(fù)制代碼 代碼如下:
[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系統(tǒng)庫(kù):
復(fù)制代碼 代碼如下:
root@webserver:/home/webmaster# mysql -u root mysql
連接到mysql庫(kù)后直接修改root帳號(hào)的密碼為新的密碼'mynewpasswd':
復(fù)制代碼 代碼如下:
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服務(wù)進(jìn)程(PID 3591見(jiàn)前面啟動(dòng)服務(wù)時(shí)的屏幕信息):
復(fù)制代碼 代碼如下:
root@webserver:/home/webmaster# kill 3591
正常啟動(dòng) mysql服務(wù),并用新密碼登錄mysql服務(wù)器成功:
復(fù)制代碼 代碼如下:
root@webserver:/home/webmaster#service mysql start
root@webserver:/home/webmaster#mysql -u root -pmynewpasswd
相關(guān)文章
MySQL開(kāi)啟記錄執(zhí)行過(guò)的SQL語(yǔ)句方法
這篇文章主要介紹了MySQL開(kāi)啟記錄執(zhí)行過(guò)的SQL語(yǔ)句方法,配置的方法很簡(jiǎn)單,本文直接給出配置示例,需要的朋友可以參考下2015-07-07SQL實(shí)現(xiàn)對(duì)數(shù)據(jù)庫(kù)檢索數(shù)據(jù)的直接轉(zhuǎn)換計(jì)算
這篇文章主要介紹了SQL實(shí)現(xiàn)對(duì)數(shù)據(jù)庫(kù)檢索數(shù)據(jù)的直接轉(zhuǎn)換計(jì)算,文章圍繞主題展開(kāi)詳細(xì)的內(nèi)容介紹,具有一定的參考價(jià)值,需要的小伙伴可以參考一下2022-09-09MySQL錯(cuò)誤代碼3140:無(wú)效的JSON文本編碼問(wèn)題解決辦法
下面這篇文章主要給大家介紹了關(guān)于MySQL錯(cuò)誤代碼3140:無(wú)效的JSON文本編碼問(wèn)題的解決辦法,文中通過(guò)代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用mysql具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2024-03-03MySQL控制用戶(hù)輸錯(cuò)密碼嘗試次數(shù)
這篇文章主要介紹了MySQL如何控制用戶(hù)輸錯(cuò)密碼嘗試次數(shù),文中給大家提到了死鎖監(jiān)控方法及處理方案,需要的朋友可以參考下2019-11-11mysql中文排序注意事項(xiàng)與實(shí)現(xiàn)方法
mysql在查詢(xún)字符串時(shí)是大小寫(xiě)不敏感的,在編繹mysql時(shí)一般以ISO-8859字符集作為默認(rèn)的字符集,因此在比較過(guò)程中中文編碼字符大小寫(xiě)轉(zhuǎn)換造成了這種現(xiàn)象,比較應(yīng)急的方法是對(duì)于包含中文的字段加上"binary"屬性,使之作二進(jìn)制比較2008-09-09