在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出現(xiàn)2003錯(cuò)誤的三種解決方法
本文主要介紹了MySQL出現(xiàn)2003錯(cuò)誤的解決方法,主要介紹了3種方法,具有一定的參考價(jià)值,感興趣的可以了解一下2023-09-09
mysql中使用sphinx搜索子域名需注意的問(wèn)題
比如搜索jb51.net會(huì)把www.dhdzp.com、jb51.net、sc.jb51.net等都搜索出來(lái)2013-02-02
MySQL自動(dòng)填充create_time和update_time的兩種方式
當(dāng)我們創(chuàng)建業(yè)務(wù)表的時(shí)候 通常都需要設(shè)置create_time 和 update_time,下面這篇文章主要給大家介紹了關(guān)于MySQL自動(dòng)填充createTime和updateTime的兩種方式,需要的朋友可以參考下2022-05-05
mysql8.0.0 winx64.zip解壓版安裝配置教程
這篇文章主要為大家詳細(xì)介紹了mysql8.0.0 winx64.zip解壓版安裝配置教程,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-05-05
使用MySQL MySqldump命令導(dǎo)出數(shù)據(jù)時(shí)的注意事項(xiàng)
這篇文章主要介紹了使用MySQL MySqldump命令導(dǎo)出數(shù)據(jù)時(shí)的注意事項(xiàng),很實(shí)用的經(jīng)驗(yàn)總結(jié),需要的朋友可以參考下2014-07-07

